【问题标题】:How to catch custom SOAP Header localPart Request in Spring Boot如何在 Spring Boot 中捕获自定义 SOAP 标头 localPart 请求
【发布时间】:2017-11-12 07:45:02
【问题描述】:

我有一个名为 RequestSOAPHeader 的 POJO 类,用于 SOAP 标头。

在@Endpoint 中,我正在捕获如下标题

@SoapHeader("{" + RequestSOAPHeader.AUTH_NS + "}RequestSOAPHeader")SoapHeaderElement auth

我的问题是当我试图在 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>

我正在使用以下方法来解组我的标题

 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;
}

根据错误,我已将标头 localPart 名称更改为 requestSOAPHeader 并且工作正常。

@SoapHeader("{" + RequestSOAPHeader.AUTH_NS + "}requestSOAPHeader")SoapHeaderElement auth

但我想使用 RequestSOAPHeader 作为标头的 localPart,而不是 requestSOAPHeader

【问题讨论】:

  • 你有没有implements SOAPHandler&lt;SOAPMessageContext&gt;的课?
  • 没有。我没有使用任何实现 SOAPHandler 的类。我正在使用提到的方法 getAuthentication(SoapHeaderElement header) 来解组标头。

标签: java xml spring-boot soap soapheader


【解决方案1】:

我已经找到了解决办法。

只需在标头类顶部添加以下 sn-p @annotation 值。希望对你有帮助

@XmlRootElement(namespace = "http://www.gooogle.com", name = "RequestSOAPHeader")
public class RequestSOAPHeader{
....
}

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 2022-11-30
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多