I resolved this problem by changing my input and output types from DOMSource to String. And then Using a javax.xml.transform.Transformer to convert my Document to the response String. This gives me more control over the response xml and I can turn on the XML declaration if I want to by setting a property on the transformer. transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
Thanks for you help. miles On 4/25/13 2:42 PM, "Poindexter, Miles" <[email protected]> wrote: >Thank you Sergey, >Yes, this is a REST service built on a JAXWS Provider. >I have tried doing it two ways, one way uses an OSGi bundle activator to >create the HTTP endpoint, and there is no configuration file. So I don't >know how to set the JAXB Marshaller property, because the only object I'm >seeing is the DOMSource. > >The other way I tried it is with regular JAXB annotations creating REST >service and giving it an HTTP endpoint by using a blueprint configuration >file. This would be my preferred way to create REST services going >forward. >But I don't know how to set the JAXB Marshaller property in the blueprint >file. I tried this: > ><bean id="greetingBean" class="com.cn.dsa.service.GreetingServiceImpl"/> > > <jaxrs:server id="greetingService" address="/greeting"> > <jaxrs:serviceBeans> > <ref component-id="greetingBean" /> > </jaxrs:serviceBeans> > > <jaxrs:dataBinding> > <bean class="org.apache.cxf.jaxb.JAXBDataBinding"> > <property name="marshallerProperties"> > <map> > <entry> > ><key><value>com.sun.xml.bind.xmlDeclaration</value></key> > <value type="boolean">true</value> > </entry> > </map> > </property> > </bean> > </jaxrs:dataBinding> > > </jaxrs:server> > >But I get this error: >org.apache.cxf.interceptor.Fault: Unmarshalling Error: >javax.xml.transform.dom.DOMSource is not known to this context > at >org.apache.cxf.jaxrs.provider.DataBindingProvider.readFrom(DataBindingProv >i >der.java:76) > at >org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils >. >java:1189) > at >org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java: >1 >137) > at >org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:686 >) > at >org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:64 >6 >) > at >org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSIn >I >nterceptor.java:237) > at >org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInI >n >terceptor.java:98) > at >org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorCha >i >n.java:271) > at >org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiation >O >bserver.java:121) > at >org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPD >e >stination.java:239) > at >org.apache.cxf.transport.servlet.ServletController.invokeDestination(Servl >e >tController.java:218) > at >org.apache.cxf.transport.servlet.ServletController.invoke(ServletControlle >r >.java:163) > at >org.apache.cxf.transport.servlet.ServletController.invoke(ServletControlle >r >.java:137) > at >org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringSe >r >vlet.java:158) > at >org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstrac >t >HTTPServlet.java:243) > at >org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPSe >r >vlet.java:163) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:713) >. . . > > > > >-- >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/miles_poindexter@cond >e >nast.com> > > > > > >On 4/24/13 5:07 PM, "Sergey Beryozkin" <[email protected]> wrote: > >>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-9A >>>8 >>>FCE0ED464/[email protected]> >>> >>> >>> >> >> >>-- >>Sergey Beryozkin >> >>Talend Community Coders >>http://coders.talend.com/ >> >>Blog: http://sberyozkin.blogspot.com > >
