I have a problem with a SOAP service which returns XML documents directly embedded in the SOAP XML. The SOAP Response looks like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header />
<soap:Body xmlns="WebserviceNamespace">
<Result xmlns="WebserviceNamespace">
<ActualXmlDocument DtdRelease="0" DtdVersion="4" xmlns="">
...
</ActualXmlDocument>
</Result>
</soap:Body>
</soap:Envelope>
The content type of <Result>
according to the WSDL is
<s:element minOccurs="0" maxOccurs="1" name="Result">
<s:complexType mixed="true">
<s:sequence>
<s:any />
</s:sequence>
</s:complexType>
</s:element>
For the <ActualXmlDocument>
I have generated Java classes with xjc
from a provided XSD file. For the webservice implementation I am using javax.jws/javax.jws-api/1.1
, javax.xml.ws/jaxws-api/2.3.1
and com.sun.xml.ws/rt/2.3.1
. The Type of the Object representing the <ActualXmlDocument>
I retrieve from my WS implementation is com.sun.org.apache.xerces.internal.dom.ElementNSImpl
which implements org.w3c.dom.Node
. When trying to unmarshal with JAXB
JAXBContext context = JAXBContext.newInstance(ActualXmlDocument.class);
context.createUnmarshaller().unmarshal((Node)result);
I get the following Exception
UnmarshalException:
unexpected element (URI:"WebserviceNamespace", local:"ActualXmlDocument").
Expected elements are <{}ActualXmlDocument>
so for some reasons the empty Namespace is not taken as new default Namespace when reading the XML Document but rather is overwritten by the WebseriveNamespace which is misplaced there.
So how can I resolve this issue? I don't want to touch the generated files from the XSD just to fit this obviously wrong behaviour. Also I am not in control of the server side of the webservice so I can not change its behaviour. The only possibility I see right now is JAXB: How to ignore namespace during unmarshalling XML document?
Is there some other way to get the Node with the correct Namespace?
EDIT: This is actually a bug in the com.sun.xml.ws.api.message.saaj.SaajStaxWriter, which is solved in JDK 1.8.0u172 but unfortunately not in JAX WS itself.