将子元素添加到 Spring-WS 中的自定义 SOAP 标头 [英] Add child elements to custom SOAP header in Spring-WS

查看:22
本文介绍了将子元素添加到 Spring-WS 中的自定义 SOAP 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring-WS 调用 SOAP 网络服务.有问题的网络服务要求我在 SOAP 标头中传递一些信息,如下所示:

I am calling a SOAP webservice with Spring-WS. The webservice in question requires me to pass some information in the SOAP header as shown here:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      <CustomHeaderElement>
         <clientID>xyz</clientID>
         <wsdlVersion>1.0</wsdlVersion>
         <serviceType>ExampleService_v1</serviceType>
      </CustomHeaderElement>
   </soapenv:Header>
   <soapenv:Body>
   ...
   </soapenv:Body>
</soapenv:Envelope>

我已经弄清楚如何拥有顶级 CustomHeaderElement,但我在 Spring-WS API 中没有看到任何允许我添加子元素的内容.这是我目前所拥有的:

I've figured out how to had the top level CustomHeaderElement, but I don't see anything in the Spring-WS API that allows me to add a child element. Here is what I have so far:

WebServiceTemplate template = ...;

template.marshalSendAndReceive(request, new WebServiceMessageCallback(){
    public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException{
        SoapMessage soapMessage = (SoapMessage)message;
        SoapHeader soapHeader = soapMessage.getSoapHeader();
        QName qName = new QName("CustomHeaderElement");
        SOAPHeaderElement headerElement = soapHeader.addHeaderElement(qName);
        //would like to do something like headerElement.addChild(clientIdNode);
    }
});

问题是 headerElement 似乎没有公开任何实际添加子项的方法.我知道我可以添加一个属性,但这不是这个服务调用所需要的.有谁知道如何将必要的子元素添加到我的自定义标题中?

The problem is headerElement doesn't seem to expose any means of actually adding a child. I know I can add an attribute, but that's not what I need for this service call. Does anyone know how I could add the necessary child elements to my custom header?

推荐答案

我对这个解决方案并不满意,但事实证明您实际上可以将消息转换为 SOAPMessage,这样您就可以完全访问所有 SAAJ api.从那里你可以在标题中构建任何你想要的元素.

I'm not pleased with this solution, but as it turns out you can actually cast the message to a SOAPMessage which gives you full access to all the SAAJ apis. From there you can build whatever elements you want inside the header.

这篇关于将子元素添加到 Spring-WS 中的自定义 SOAP 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆