[英]How to catch custom SOAP Header localPart Request in Spring Boot
I have POJO class named RequestSOAPHeader for SOAP Header. 我有一个名为RequestSOAPHeader的 POJO类,用于SOAP Header。
In the @Endpoint I am catching the header like below 在@Endpoint中,我正在捕获标题,如下所示
@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. 我的问题是,当我尝试在POJO类中解组标题时,出现以下错误。
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. 根据错误,我已将标头localPart名称更改为requestSOAPHeader ,并且工作正常。
@SoapHeader("{" + RequestSOAPHeader.AUTH_NS + "}requestSOAPHeader")SoapHeaderElement auth
But I want to use RequestSOAPHeader as localPart for header, not requestSOAPHeader 但是我想将RequestSOAPHeader用作header的localPart,而不是requestSOAPHeader
I have already found the solution. 我已经找到了解决方案。
Just add the following snippet @annotation
value on top of the header class. 只需在标头类顶部添加以下代码段
@annotation
值即可。 Hope it helps 希望能帮助到你
@XmlRootElement(namespace = "http://www.gooogle.com", name = "RequestSOAPHeader")
public class RequestSOAPHeader{
....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.