简体   繁体   中英

How to catch custom SOAP Header localPart Request in Spring Boot

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{
....
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM