1

「標準」の ws アドレス指定ヘッダーを cxf クライアント呼び出しに単純に追加する方法を理解しています。

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

しかし、メッセージの SOAP ヘッダーが次のようになるように 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 クライアント呼び出し内にこのヘッダーを追加するにはどうすればよいですか?

よろしく、土壌労働者

4

1 に答える 1

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 doc (これ以上リンクを投稿することはできません..) およびhttp://cxf.547215.n5.nabble.com/setting-reference-parameters-in-WS-Addressing-header-td3257262。 html
私は JAXB に詳しくありませんが、ref にパラメーターを追加するには、JAXB の方が良い方法だと思います。

于 2014-06-23T11:51:44.847 に答える