Getting the raw XML parameter in the JAX-WS web service method

How to achieve something like this:

@WebService(endpointInterface = "ru.citc.techtest.cxfconcepts.HelloWorld") public class HelloWorldImpl implements HelloWorld { public String sayHi(DOMSource xml) { return "Hello"; } } 

I need raw XML for processing (SAX or DOM). At the same time, I want to use the existing JAX-WS method routing (I use Apache CXF) The return value can be of any type.

+4
source share
1 answer

I believe this will work:

 @WebService(wsdlLocation = "....") @DataBinding(org.apache.cxf.databinding.source.SourceDataBinding.class) @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) public class HelloWorldImpl implements HelloWorld { public Source sayHi(Source xml) { return xml; } } 

By default, you should get a StaxSource (which is a subclass of SAXSource) so that you can pass this into your XML processing library and the like. You can return any subclass of Source. However, you can also be more specific and use:

 public Source sayHi(DOMSource xml) 

if you know that you need it as a DOM. I really think:

 public Source sayHi(XMLStreamReader xml) 

will work too.

+3
source

All Articles