Hi
On 24/04/13 20:29, Poindexter, Miles wrote:
Hello to everyone on the list.
I'm a new developer using ServiceMix and building some REST services using CXF 
and JAX-RS 2.0 which uses javax.xml.ws.Provider.

FYI, in this case your are working with JAX-WS API,
In this case you should probably configure JAXB DataBinding in your jaxws endpoint and set up a JAXB Marshaller property (com.sun.xml.bind.xmlDeclaration) which will instruct JAXB to retain the declaration

You can see an example at
http://cxf.apache.org/docs/jaxb.html

Sergey


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?

To test this, I built a stripped down service that looks like this:

@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/test")) {
                 return testResponse();
             }
         }
   }

private DOMSource testResponse() {
         DocumentBuilderFactory factory;
         DocumentBuilder builder;
         Document document = null;
         DOMSource response = null;

         try {
             factory = DocumentBuilderFactory.newInstance();
             //factory.setValidating(true);
             builder = factory.newDocumentBuilder();
             InputStream testResponse = 
getClass().getResourceAsStream("/files/test.xml");

             document = builder.parse(testResponse);
             response = new DOMSource(document);
         } catch (Exception e) {
             e.printStackTrace();
         }
         return response;
     }
}

This service grabs an xml file that has the XML declaration, creates the 
Document from it, and then the DOMSource from the Document and returns the 
DOMSource.

test.xml  file:
[code]
<?xml version="1.0" encoding="utf-8" ?>
<Test>
   <name>John</name>
   <id>123456</id>
</Test>

But the service returns only:
<Test>
   <name>John</name>
   <id>123456</id>
</Test>

What is the recommended way in the current version of ServiceMix to get this 
response to NOT strip out the XML declaration?

miles
--
Miles Poindexter
Data&  Service Architecture
Condé Nast
ph: 212-790-6692
mobile: 347-967-8944
fax: 212-790-1891
[email protected]<applewebdata://6D7C2D39-4D16-42A7-8457-9A8FCE0ED464/[email protected]>





--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to