我该如何动态改变我的JAXWS客户端所使用的地址?此客户端是通过wsimport生成的。
我该如何动态改变我的JAXWS客户端所使用的地址?此客户端是通过wsimport生成的。
/**
* The following snippets shows how to set a custom endpoint for a JAX-WS generated WebClient on runtime
*/
// Get the service and the port
SampleService service = new SampleService();
Sample port = service.getESamplePort();
// Use the BindingProvider's context to set the endpoint
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.aviramsegal.com/ws/sample");
/* Optional credentials */
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
port.callSampleMethod();
getPort
时都会创建一个新的端口对象。 - Christopher Schneider使用Apache CXF解决了这个问题。
只需要两行代码!以下是代码片段:
URL url_wsdl = new URL("http://myserver/myservice?wsdl");
Service service = Service.create(url_wsdl, new QName("http://myaddress...", "ServiceName"));
return service.getPort(MyJAXWSPortClass.class);
我是PayPal集成的新手,不确定Adaptive Payment API。但我们可以通过GetVerifiedStatus方法检查特定电子邮件ID是否在PayPal中有帐户。
请使用以下沙盒WSDL URL验证电子邮件
URL: https://svcs.sandbox.paypal.com/AdaptiveAccounts?wsdl
响应将如下所示
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns2:GetVerifiedStatusResponse xmlns:ns2="http://svcs.paypal.com/types/aa">
<responseEnvelope>
<timestamp>2015-07-20T23:42:46.661-07:00</timestamp>
<ack>Success</ack>
<correlationId>5cea9a8575ab9</correlationId>
<build>17345626</build>
</responseEnvelope>
<accountStatus>UNVERIFIED</accountStatus>
<countryCode>IN</countryCode>
<userInfo>
<emailAddress>anandg.saga@gmail.com</emailAddress>
<accountType>PERSONAL</accountType>
<accountId>6KD7EVWM2E2AQW</accountId>
<name>
<salutation/>
<firstName>anand</firstName>
<middleName/>
<lastName>anand</lastName>
<suffix/>
</name>
<businessName/>
</userInfo>
</ns2:GetVerifiedStatusResponse>
</soapenv:Body>
</soapenv:Envelope>
String endpointURL = "https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
private static void addEndPoint(AdaptiveAccountsPortType port,
String endpointURL) {
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
/*List hchain = bp.getBinding().getHandlerChain();
if (hchain == null) {
hchain = new ArrayList();
}
hchain.add(new HTTPUserAgentHandler());
bp.getBinding().setHandlerChain(hchain);*/
}
如果您使用wsimport,我不确定如何做。我曾经遇到过同样的问题,所以我使用Intellij IDEA(版本9)为我创建客户端代码。它提供了一个服务端点构造函数,可以输入wsdl url。