XML declaration for RESTful services using javax.xml.ws.Provider

One Star

XML declaration for RESTful services using javax.xml.ws.Provider

I built a few RESTful webservices using this example:
/examples/apache/cxf/restful_dispatch
which uses javax.xml.ws.Provider.
They work great.
The only glitch is now one client wants to see the XML declaration in the response XML.
They are claiming the XML is not valid without the declaration.
Even though they are wrong, and its valid, I am still curious if I can somehow get the declaration to show up?
So my service looks like:
@WebServiceProvider()
@ServiceMode(value = Service.Mode.PAYLOAD)
public class RestSourcePayloadProvider implements Provider<DOMSource> {
public DOMSource invoke(DOMSource request) {

if (httpMethod.equalsIgnoreCase("POST")) {
if (path.equals("/cxf/"+PATH+"/contract/search")) {
System.out.println("---Invoking searchContracts---");

return searchContracts(request);
}
}
}
}

The searchContracts method in the example above returns a DOMSource object, which definitely has the XML declaration in it. Yet it gets stripped out.
I think this is because this service is kind've a "hack" to run a RESTful service on top of SOAP frameworks? And since SOAP thinks the xml encoding should be sent as headers, or maybe in the HEAD part of the SOAP response, the framework strips it out of the BODY.
Can Talend introduce a way to turn this stripping action off?
If you just build and run the restful_dispatch example, you will see what I mean.
This example just grabs a static xml file for the response:
for example, the test link,
http://localhost:9000/customerservice/customer?id=1234
makes the service return the CustomJohnResp.xml file, which looks like:
<?xml version="1.0" encoding="utf-8" ?>
<Customer>
<name>John</name>
<id>123456</id>
</Customer>

But the service returns:
<Customer>
<name>John</name>
<id>123456</id>
</Customer>
Community Manager

Re: XML declaration for RESTful services using javax.xml.ws.Provider

Hi
Do you call the rest webservice in browser or in Talend Studio with ESB component? If I call a rest webservice with tRestClient or tRest component, I can see the XML declaration in the response.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: XML declaration for RESTful services using javax.xml.ws.Provider

Which web service are you calling?
Is it the web service from my example above?
/examples/apache/cxf/restful_dispatch
Many other of the RESTful examples do have the xml declaration in the response.
But this one doesn't
And I just found out this morning that PeopleSoft will not process the response unless the declaration is there.
So I either need a way to fix this,
Or I have to rewrite the webservice to use something other than javax.xml.ws.Provider
One Star

Re: XML declaration for RESTful services using javax.xml.ws.Provider

Could this problem be cause by this?
http://docs.oracle.com/javaee/5/api/javax/xml/soap/SOAPMessage.html#WRITE_XML_DECLARATION
Basically, the WRITE_XML_DECLARATION var of the javax.xml.soap.SOAPMessage object default value is "false"
I there a way via CXF to set this to "true" for my service?
Or is this a red-herring?
One Star

Re: XML declaration for RESTful services using javax.xml.ws.Provider

I wrote two test REST services that do simple greetings in xml. One uses blueprint to create the HTTP endpoint. The other uses a bundle Activator class. I can't get either one to print the xml declaration at the top of the response xml. I tried using an Inteceptor to do it but it doesn't seem to be getting triggered.
Anyway, I'm hoping there is a simple way to do this but just need some help or an example.
I'm willing to put both example here but there doesn't seem to be any activity on this forum.
Is there an IRS channel or somewhere else to ask developer questions and get help?
miles
One Star

Re: XML declaration for RESTful services using javax.xml.ws.Provider

Hi
Do you call the rest webservice in browser or in Talend Studio with ESB component? If I call a rest webservice with tRestClient or tRest component, I can see the XML declaration in the response.
Shong

Shong, which example service is this? Which folder? I have ESB 5.2.2