This question already has an answer here:
这个问题在这里已有答案:
- How to change webservice url endpoint? 3 answers
- 如何更改webservice url端点? 3个答案
How can I dynamically change the address which my JAXWS client is using? This client was generated by wsimport.
如何动态更改JAXWS客户端使用的地址?该客户端由wsimport生成。
4 个解决方案
#1
90
You can achieve that using the BindingProvider interface.
您可以使用BindingProvider接口实现此目的。
JAX-WS自定义端点
/**
* 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();
#2
11
Solved the problem using Apache CXF.
使用Apache CXF解决了这个问题。
With just two lines of code! Here is the snippet:
只需两行代码!这是片段:
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);
#3
0
I am not sure on how to do that if you use wsimport. I had the same issue, so I used Intellij IDEA (version 9) to create client code for me. It provided a service endpoint constructor that takes in the wsdl url.
如果你使用wsimport,我不知道如何做到这一点。我有同样的问题,所以我使用Intellij IDEA(版本9)为我创建客户端代码。它提供了一个服务端点构造函数,它接受wsdl url。
#4
0
I am new to PayPal integration, i am not sure about Adaptive Payment api. But we have a privilege to check whether specific email id having account in PayPal or not using GetVerifiedStatus method.
我是PayPal集成的新手,我不确定Adaptive Payment api。但我们有权使用GetVerifiedStatus方法检查特定电子邮件ID是否在PayPal中拥有帐户。
Please use below sandbox wsdl URL for verifying email
请使用下面的sandbox wsdl URL验证电子邮件
URL : https://svcs.sandbox.paypal.com/AdaptiveAccounts?wsdl
网址:https://svcs.sandbox.paypal.com/AdaptiveAccounts?wsdl
Response will be like below
回复如下
<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>
Note: while creating stub don't forgot to set endpoint as below. if we are not setting this, we can't get expected output.
注意:创建存根时不要忘记设置端点,如下所示。如果我们不设置这个,我们就无法获得预期的输出。
String endpointURL = "https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
use below method to add endpoint
使用以下方法添加端点
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);*/
}
#1
90
You can achieve that using the BindingProvider interface.
您可以使用BindingProvider接口实现此目的。
JAX-WS自定义端点
/**
* 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();
#2
11
Solved the problem using Apache CXF.
使用Apache CXF解决了这个问题。
With just two lines of code! Here is the snippet:
只需两行代码!这是片段:
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);
#3
0
I am not sure on how to do that if you use wsimport. I had the same issue, so I used Intellij IDEA (version 9) to create client code for me. It provided a service endpoint constructor that takes in the wsdl url.
如果你使用wsimport,我不知道如何做到这一点。我有同样的问题,所以我使用Intellij IDEA(版本9)为我创建客户端代码。它提供了一个服务端点构造函数,它接受wsdl url。
#4
0
I am new to PayPal integration, i am not sure about Adaptive Payment api. But we have a privilege to check whether specific email id having account in PayPal or not using GetVerifiedStatus method.
我是PayPal集成的新手,我不确定Adaptive Payment api。但我们有权使用GetVerifiedStatus方法检查特定电子邮件ID是否在PayPal中拥有帐户。
Please use below sandbox wsdl URL for verifying email
请使用下面的sandbox wsdl URL验证电子邮件
URL : https://svcs.sandbox.paypal.com/AdaptiveAccounts?wsdl
网址:https://svcs.sandbox.paypal.com/AdaptiveAccounts?wsdl
Response will be like below
回复如下
<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>
Note: while creating stub don't forgot to set endpoint as below. if we are not setting this, we can't get expected output.
注意:创建存根时不要忘记设置端点,如下所示。如果我们不设置这个,我们就无法获得预期的输出。
String endpointURL = "https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
use below method to add endpoint
使用以下方法添加端点
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);*/
}