Get the soap message header using jaxb Unmarshaller
<p>I am consuming a web-service which has the soap message header as follows.</p>

<pre><code>&lt;SOAP-ENV:Header&gt;
      &lt;MessageHeader xmlns:cnr="http://testservice.com/Namespaces/Types/Public/DataModel.xsd" xmlns="http://testservice.com/Namespaces/Types/Public/MessageHeader.xsd"&gt;
         &lt;CommonMessageHeader&gt;
            &lt;cnr:version&gt;v109&lt;/cnr:version&gt;
            &lt;cnr:dateTimeStamp&gt;2016-08-31T14:37:03Z&lt;/cnr:dateTimeStamp&gt;
            &lt;cnr:referenceId&gt;cc7b-429c-a2f5-1f61dcb94e85&lt;/cnr:referenceId&gt;
         &lt;/CommonMessageHeader&gt;
         &lt;SecurityMessageHeader&gt;
            &lt;cnr:userName&gt;dtv_directvcom&lt;/cnr:userName&gt;
            &lt;cnr:userPassword&gt;dtv_directvcom0624&lt;/cnr:userPassword&gt;
         &lt;/SecurityMessageHeader&gt;        
      &lt;/MessageHeader&gt;
   &lt;/SOAP-ENV:Header&gt;
</code></pre>

<p>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).</p>

<pre><code>unexpected element (uri:"http://testservice.com/Namespaces/Profile/Types/Public/MessageHeader.xsd", local:"MessageHeader").
Expected elements are &lt;{http://testservice.com/Namespaces/Types/Public/SoapFaultDetails.xsd}ApplicationException&gt;,
&lt;{http://testservice.com/Namespaces/Container/Public/ServiceRequest.xsd}ServiceRequest&gt;,
&lt;{http://testservice.com/Namespaces/Container/Public/ServiceResponse.xsd}ServiceResponse&gt;,
&lt;{http://testservice.com/Namespaces/Types/Public/MessageHeader.xsd}MessageHeader&gt;
</code></pre>

<p>Below is the code snippet used.</p>

<pre><code>NodeList nodeList = soapMessage.getSOAPHeader().getElementsByTagName("MessageHeader");
if ( (nodeList != null) &amp;&amp; (nodeList.getLength() &gt; 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) &amp;&amp; (value instanceof JavaObject) ) {
                    setResponseHeader((JavaObject) value);
                }
            }
        }
</code></pre>

<p>I am not sure how the MessageHeader of another service is coming as namespace URI. Can anyone help me on this please?</p>