Overriding WS Endpoint in Webservice Client
I needed to call a webservice, which had a illegal soap:address location inside of the wsdl.
Example:
<service name="ExternalWSTokenServiceImplRemoteService">
<port binding="tns:TokenServiceBinding" name="TokenServicePort">
<soap:address location="http://mydomain.com.test"/>
</port>
</service>
http://mydomain.com.test
is obviously wrong. The correct address would be https://mydomain.com
The correct way of fixing this, would be to fix the WSDL. But sometimes it just isn’t in your control. In that case, you can generate the client stub, like you always do and override the endpoint.
...
ExternalMyServiceService service = new ExternalMyServiceService(new URL("....wsdl location?wsdl"));
MyService myservice= service.getMyServicePort();
...
/* Set NEW Endpoint Location */
String endpointURL = "https://mydomain.com?wsdl";
BindingProvider bp = (BindingProvider)myservice;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);
...