【问题标题】:How to add wsa reference parameters to cxf client call?如何将 wsa 引用参数添加到 cxf 客户端调用?
【发布时间】:2014-06-15 03:17:29
【问题描述】:

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

JaxWsProxyFactoryBean factory = ...;
factory.getFeatures().add(new WSAddressingFeature());

但我不完全明白如何添加 wsa 引用参数,以便消息的肥皂标题如下所示:

<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 客户端调用中添加此标头?

亲切的问候, 土工

【问题讨论】:

  • 在调用中添加拦截器是最佳做法吗?

标签: java cxf ws-addressing reference-parameters


【解决方案1】:

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

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 添加参数的更好方法。

【讨论】:

  • 谢谢你的回答,我已经用拦截器添加了我的参考参数,但是你提供的答案/解决方案看起来比我的好:)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-04
  • 2014-01-15
  • 1970-01-01
相关资源
最近更新 更多