首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在cxf客户端调用中添加wsa引用参数?

如何在cxf客户端调用中添加wsa引用参数?
EN

Stack Overflow用户
提问于 2014-04-29 09:11:51
回答 1查看 2.3K关注 0票数 1

我理解如何简单地将“标准”ws寻址头添加到cxf客户端调用:

代码语言:javascript
复制
JaxWsProxyFactoryBean factory = ...;
factory.getFeatures().add(new WSAddressingFeature());

但我不太清楚如何添加wsa引用参数,以便消息的soap头看起来如下所示:

代码语言:javascript
复制
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://www.w3.org
/2005/08 /addressing" xmlns:ns1=... >
<soap:Header>
  <wsa:To>...</wsa:To>
  <wsa:Action>...</wsa:Action>
  <wsa:MessageID>...</wsa:MessageID>
  <ns1:Country wsa:IsReferenceParameter="true">xx</ns1:Country>
  <ns1:Brand wsa:IsReferenceParameter="true">x</ns1:Brand>
</soap:Header> ...

如何在cxf客户端调用中添加此标头?

好心的问候,土工

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-23 11:51:44

这可以在AddressingProperties的帮助下完成。

代码语言:javascript
复制
factory.setServiceClass(...);
factory.setAddress(...);
factory.getFeatures().add(new WSAddressingFeature());
SomePortType client = (SomePortType) factory.create();
AddressingProperties maps = new AddressingPropertiesImpl();
EndpointReferenceType epr = new EndpointReferenceType();

//Then you can add referenceParameters to the epr
ReferenceParametersType ref = new ReferenceParametersType();
List<Object> paras = ref.getAny();
Country ctry = new Country("xx");

JAXBContext ctx = JAXBContext.newInstance(new Class[] {Country.class });
Marshaller marshaller = ctx.createMarshaller();
DOMResult res = new DOMResult();
marshaller.marshal(ctry, res);
Element elt = ((Document) res.getNode()).getDocumentElement();
any.add(elt);

epr.setReferenceParameters(ref);
maps.setTo(epr);

((BindingProvider)client).getRequestContext()
    .put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, maps);

参考资料:关于ws-addr的cxf文档(我不能发布更多的链接,叹息)和http://cxf.547215.n5.nabble.com/setting-reference-parameters-in-WS-Addressing-header-td3257262.html

我不熟悉JAXB,我认为它们可以更好地向ref添加参数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23360361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档