使用CXF(实际上是GroovyWS),如何生成一个带有一个文本节点的子节点的SOAP头? [英] With CXF (actually GroovyWS), how do I generate a SOAP header with one child node having a text node?

查看:169
本文介绍了使用CXF(实际上是GroovyWS),如何生成一个带有一个文本节点的子节点的SOAP头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  

<肥皂:页眉和GT;
< HeaderInfo xmlns =http://foo.bar.com/ns>
< token> abc-unique-token< / token>
< / HeaderInfo>
< / soap:Header>

我发现将标题添加到CXF消息的常见问题,它让我几乎在那里,但不是很完美。他们给选项4的例子如下所示:

  List< Header> header = new ArrayList< Header>()
Header header = new Header(new QName(http://foo.bar.com/ns,HeaderInfo),
abc-unique-新的JAXBDataBinding(String.class))
headers.add(header)

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

使用这段代码,我可以做到这一点:

 <肥皂:页眉和GT; 
< HeaderInfo xmlns =http://foo.bar.com/ns>
abc-unique-token
< / HeaderInfo>
< / soap:Header>

但是,HeaderInfo节点缺少子节点令牌节点以环绕abc-unique-令牌,我不知道如何在那里得到它。

是否有一些简单的事情可以传递给Header构造函数来创建该节点?

A 单独发帖讨论使用不同的技术,但是当我尝试使用它时,会在SoapFactory的周围引发错误。



我发现的其他许多东西都需要用一堆附加代码创建一些扩展AbstractPhaseInterceptor类的东西,当我想要的东西太接近时:)。$ b $在解决了我提到的单独的帖子中的SOAPFactory方法需要saaj-impl.jar才能工作之后,我才得以使用这个方法:

 列表< Header> headers = new ArrayList< Header>()
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对于使用CXF推荐的方式,并为Header类添加节点子节点,我仍然好奇(并且会接受答案)。


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

<soap:Header>
    <HeaderInfo xmlns="http://foo.bar.com/ns">
        <token>abc-unique-token</token>
    </HeaderInfo>
</soap:Header>

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<Header> headers = new ArrayList<Header>()
    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:

<soap:Header>
    <HeaderInfo xmlns="http://foo.bar.com/ns">
        abc-unique-token
    </HeaderInfo>
</soap:Header>

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<Header> headers = new ArrayList<Header>()
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.

这篇关于使用CXF(实际上是GroovyWS),如何生成一个带有一个文本节点的子节点的SOAP头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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