我想用JAX-WS API创建的WS-Addressing支持Web服务客户端。 我用的wsimport创建从WSDL文件的客户端存根,并可启用/禁用WS-Addressing的使用AddressingFeature,如
Hello hello = service.getHelloSoap11(new AddressingFeature(true, true));
但是,我无法找到该网页自定义的WS-Addressing的ReplyTo / FaultTo端点引用的任何样品。 基本上,我想创建像下面(参见WSA:的ReplyTo元件)一个WS请求:
<soapenv:Envelope ...>
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To soapenv:mustUnderstand="1">http://localhost:8080/poc/helloService/
</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://mycompany.com/poc/reply</wsa:Address>
<wsa:ReferenceParameters>
<field1 xmlns="http://mycompany.com/poc/cust">some value1</field1>
<field2 xmlns="http://mycompany.com/poc/cust">some value2</field2>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:Action>http://mycompany.com/poc/sayHello</wsa:Action>
<wsa:MessageID>urn:uuid:7849b04f-c74e-4836-99e4-8e25d2700fae
</wsa:MessageID>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
我如果可以使用Spring Web服务客户端添加端点引用。 不过,我需要使用JAX-WS做到这一点。 有任何想法吗?
我回答我的问题。
看来,标准JAX-WS API没有提供一种方便的方式来定制的WS-Addressing从/的ReplyTo / FaultTo端点引用。 然而,每个JAX-WS运行可以提供额外的专有API来设置的标头。
例如,IBM JAX-WS RI提供EndpointReferenceManager SPI来创建端点引用:
import com.ibm.wsspi.wsaddressing.EndpointReference;
import com.ibm.wsspi.wsaddressing.EndpointReferenceManager;
import com.ibm.wsspi.wsaddressing.WSAConstants;
public void testWSAddressing () {
// get the port
Hello hello = service.getHelloSoap11();
// build a EndpiontReference of <wsa:ReplyTo>
BindingProvider bp = (BindingProvider) hello;
EndpointReference epr = EndpointReferenceManager.createEndpointReference(new URI(
"http://www.w3.org/2005/08/addressing/anonymous"));
epr.setReferenceParameter(new QName("http://mycompany.com/test", "someRefParam"),
"12345678");
((BindingProvider) hello).getRequestContext()
.put(WSAConstants.WSADDRESSING_REPLYTO_EPR, epr);
...
HelloResponse response = hello.hello(request);
}
上面的代码,的IBM WebSphere内运行时,会产生如下所示的SOAP消息:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://localhost:8080/poc/helloService/</wsa:To>
<wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous
</wsa:Address>
<wsa:ReferenceParameters>
<someRefParam xmlns="http://mycompany.com/test">12345678</someRefParam>
</wsa:ReferenceParameters>
</wsa:ReplyTo>
<wsa:MessageID>urn:uuid:BE9E173A35BAB51CB31338454394298
</wsa:MessageID>
<wsa:Action>http://mycompany.com/Hello</wsa:Action>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope >
我已经找到一种方法与标准的JAX-WS做到这一点。 当得到一个端口,同时使用AddressingFeature和OneWayFeature。
AddressingFeature addressingfeature = new AddressingFeature();
OneWayFeature onewayfeature = new OneWayFeature(true, new WSEndpointReference(YOUR_REPLY_TO_ADDRESS, AddressingVersion.W3C));
// get the port
Hello hello = service.getHelloSoap11(addressingfeature, onewayfeature);
这将产生“的ReplyTo”标记的邮件。 您可能必须抓住这个“com.sun.xml.ws:jaxws-rt”的依赖。