I have POJO class named RequestSOAPHeader for SOAP Header.
In the @Endpoint I am catching the header like below
@SoapHeader("{" + RequestSOAPHeader.AUTH_NS + "}RequestSOAPHeader")SoapHeaderElement auth
My problem is when I am trying to unmarshall my header in POJO class i am having the following error.
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.test.com/schema/common/v2_1", local:"RequestSOAPHeader"). Expected elements are <{http://www.test.com/schema/common/v2_1}requestSOAPHeader>
I am using the following method for unmarsahlling my header
private RequestSOAPHeader getAuthentication(SoapHeaderElement header){
RequestSOAPHeader authentication = null;
try {
JAXBContext context = JAXBContext.newInstance(RequestSOAPHeader.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
authentication = (RequestSOAPHeader) unmarshaller.unmarshal(header.getSource());
} catch (JAXBException e) {
e.printStackTrace();
}
return authentication;
}
According to the error I have changed my header localPart name to requestSOAPHeader and it works fine.
@SoapHeader("{" + RequestSOAPHeader.AUTH_NS + "}requestSOAPHeader")SoapHeaderElement auth
But I want to use RequestSOAPHeader as localPart for header, not requestSOAPHeader
I have already found the solution.
Just add the following snippet @annotation
value on top of the header class. Hope it helps
@XmlRootElement(namespace = "http://www.gooogle.com", name = "RequestSOAPHeader")
public class RequestSOAPHeader{
....
}