JAXWS — how to change the endpoint address [duplicate]

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();

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);

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);*/
    }