Creating Dynamic EJB Proxies to JAX-WS External WebServices using the Dispatch API

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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Mark Foster, Obernai, France

I work for Sun in a team called FAST helping to enable the open source community for Open ESB.

Search

Categories
Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today