gpt4 book ai didi

web-services - 如何在 JAX-WS 客户端中指定 ReplyTo EndpointReference?

转载 作者:行者123 更新时间:2023-12-04 03:57:26 25 4
gpt4 key购买 nike

我想使用 JAX-WS API 创建启用 WS-Addressing 的 Web 服务客户端。我使用 wsimport 从 WSDL 文件创建客户端 stub ,并且可以通过使用 AddressingFeature 启用/禁用 WS-Addressing,例如

Hello hello = service.getHelloSoap11(new AddressingFeature(true, true));

但是,我在 Web 中找不到任何自定义 WS-Addressing ReplyTo/FaultTo 端点引用的示例。基本上我想创建一个像下面这样的 WS 请求(参见 wsa:ReplyTo 元素):
<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 Service 客户端,我可以添加端点引用。但是,我需要使用 JAX-WS 来完成。有任何想法吗?

最佳答案

我回答我自己的问题。

似乎标准 JAX-WS API 没有提供一种方便的方法来自定义 WS-Addressing From/ReplyTo/FaultTo 端点引用。但是,每个 JAX-WS 运行时都可能提供额外的专有 API 来设置 header 。

例如,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 >

关于web-services - 如何在 JAX-WS 客户端中指定 ReplyTo EndpointReference?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10813220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com