cxf 生成soap_使用CXF(实际上是GroovyWS),如何生成一个带有一个文本节点的子节点的SOAP头?...

I'm creating a Groovy client for a .net SOAP service that requires a soap header that looks like this:

abc-unique-token

I found the faq for adding headers to CXF messages and it gets me almost there, but not quite. The example they give for option 4 looks like this:

List headers = new ArrayList()

Header header = new Header(new QName("http://foo.bar.com/ns", "HeaderInfo"),

"abc-unique-token", new JAXBDataBinding(String.class))

headers.add(header)

proxy.client.getRequestContext().put(Header.HEADER_LIST, headers)

Using this code, I can get it to do this:

abc-unique-token

But the "HeaderInfo" node is missing the child "token" node to surround "abc-unique-token" and I'm not sure how to get it in there.

Is there some simple thing that I can pass to the Header constructor to create that node?

A separate post talks about using a different technique, but this throws errors for me around the SoapFactory when I try to use it.

Much of the other stuff that I've found gets into needing to create something extending an AbstractPhaseInterceptor class with a bunch of additional code, when what I want is so close :).

解决方案

I was able to get it to work using this after figuring out that the SOAPFactory method in the separate post that I mentioned needed saaj-impl.jar to work:

List headers = new ArrayList()

SOAPFactory sf = SOAPFactory.newInstance()

def authElement = sf.createElement(new QName("http://foo.bar.com/ns", "HeaderInfo"))

def tokenElement = authElement.addChildElement("token")

tokenElement.addTextNode("abc-unique-token")

SoapHeader tokenHeader = new SoapHeader(

new QName("http://foo.bar.com/ns", "HeaderInfo"), authElement);

headers.add(tokenHeader);

proxy.client.getRequestContext().put(Header.HEADER_LIST, headers)

I'm still curious (and would accept an answer) around doing it the CXF recommended way and adding a node child to the Header class.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值