I am consuming a web-service which has the soap message header as follows.
<SOAP-ENV:Header>
<MessageHeader xmlns:cnr="http://testservice.com/Namespaces/Types/Public/DataModel.xsd" xmlns="http://testservice.com/Namespaces/Types/Public/MessageHeader.xsd">
<CommonMessageHeader>
<cnr:version>v109</cnr:version>
<cnr:dateTimeStamp>2016-08-31T14:37:03Z</cnr:dateTimeStamp>
<cnr:referenceId>cc7b-429c-a2f5-1f61dcb94e85</cnr:referenceId>
</CommonMessageHeader>
<SecurityMessageHeader>
<cnr:userName>dtv_directvcom</cnr:userName>
<cnr:userPassword>dtv_directvcom0624</cnr:userPassword>
</SecurityMessageHeader>
</MessageHeader>
</SOAP-ENV:Header>
I am trying to convert this soap header into java object after getting response but facing below error.I am getting the response properly (compared with SoapUI).
unexpected element (uri:"http://testservice.com/Namespaces/Profile/Types/Public/MessageHeader.xsd", local:"MessageHeader").
Expected elements are <{http://testservice.com/Namespaces/Types/Public/SoapFaultDetails.xsd}ApplicationException>,
<{http://testservice.com/Namespaces/Container/Public/ServiceRequest.xsd}ServiceRequest>,
<{http://testservice.com/Namespaces/Container/Public/ServiceResponse.xsd}ServiceResponse>,
<{http://testservice.com/Namespaces/Types/Public/MessageHeader.xsd}MessageHeader>
Below is the code snippet used.
NodeList nodeList = soapMessage.getSOAPHeader().getElementsByTagName("MessageHeader");
if ( (nodeList != null) && (nodeList.getLength() > 0) ) {
Node header = nodeList.item(0);
JAXBElement jaxbElement = null;
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
jaxbElement = (JAXBElement) unmarshaller.unmarshal(header);
if (jaxbElement != null) {
Object value = jaxbElement.getValue();
if ( (value != null) && (value instanceof JavaObject) ) {
setResponseHeader((JavaObject) value);
}
}
}
I am not sure how the MessageHeader of another service is coming as namespace URI. Can anyone help me on this please?