As a follow up to the last blog entry, how can we handle a similar situation
for JAX-WS webservices where we need to change
the value of the endpoint dynamically at runtime ? Using the Dispatch API again....
This is a common requirement - imagine the situation where you have an external webservice hosted on several servers, each with its own endpoint address. Then you place a H/W load-balancer in front and use WSImport to get the WSDL - which WSDL and endpoint do you get ? Whichever one the H/W loadbalancer routes you to.
But, in your WS Client you need to use the endpoint of the H/W load-balancer, not one of the servers - you can do this using the Dispatch API as follows.....
1. Use the an example doc/literal webservice - this (US-centric) one which removes profanities from a text string will do
2. Create a EJB project inside NetBeans
3. Create a WSDL to expose your EJB as a webservice
4. Do create a WebService Client this time
5. Start coding, begin by dropping the "Profanity.asmx/Profanity/ProfanitySoap/ProfanityFilter" operation to generate the WS client call. The code below shows how to call the above webservice and respond with the profanity-free string, the only bit of code which does the dynamic work is....
Map requestContext = ((BindingProvider)port).getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://ws.cdyne.com/ProfanityWS/Profanity.asmx");
6. Attached is the EJB project. To test just create a WS client from the EJB-WS.












