A JAX-WS service defined using @WebService
and @WebMethod
makes use of JAXB to turn the XML into a Java object. For most use cases, this is great!
However, I need to interface with some legacy code written using Axis 1 which exclusively operates on org.w3c.dom.Element
objects - in other words, I'd effectively just have to transform the parameters straight back into XML as soon as I got them, which seems horrendously inefficient.
Therefore, I've been looking for a way to receive and return raw XML from a JAX-WS service, either just as a string or as objects.
I've been able to get the functionality I need by using @WebServiceProvider
and implementing the Provider<Source>
interface, but this feels a little too low-level for the kind of thing I'm doing - I can't use @WebMethod
to easily set up routing; instead I have to get the PATH_INFO
from WebServiceContext
and fiddle with the string to get the information I need.
So my question is, is there a way to make use of raw XML (effectively cutting out JAXB) in a JAX-WS service without dropping down to the @WebServiceProvider
level?
I just stumbled across the answer by myself, so here it is for anyone else who has this issue:
As mentioned in the documentation, JAXB can marshal xsd:anyType
into Object
. The concrete type of the resulting Object is apache.xerces.internal.dom.ElementNSImpl
, which is an implementation of org.w3c.dom.Element
- i.e. exactly what I need!
Therefore the solution to my problem was simply to use Object
as the parameter and return types in my method. Not a massively clean feeling solution, but it works.