Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXWS — how to change the endpoint address [duplicate]

How can I dynamically change the address which my JAXWS client is using? This client was generated by wsimport.

like image 572
Kico Lobo Avatar asked Mar 01 '11 18:03

Kico Lobo


3 Answers

You can achieve that using the BindingProvider interface.

JAX-WS custom endpoint

/**
 * 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();
like image 87
Aviram Segal Avatar answered Sep 19 '22 06:09

Aviram Segal


Solved the problem using 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);
like image 40
Kico Lobo Avatar answered Sep 23 '22 06:09

Kico Lobo


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.

Please use below sandbox wsdl URL for verifying email

URL : 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>[email protected]</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);*/
    }
like image 39
Anand saga Avatar answered Sep 21 '22 06:09

Anand saga