Pages

Multiple webservice implementation classes available at the same time under WAS7

If you want to experiment with webservices by providing several alternative implementations of the same webservice (represented by the element), each having its own URL, and you’re using Websphere 7 and JAX-WS, then:

1. For each alternative implementation, add with a unique name under the element in the WSDL file. Beware: This is essential to enable multiple implementations.
2. For each alternative implementation, define a servlet and servlet mapping in web.xml like this:
view source
print?
1
2 $IMPLEMENTATION_CLASS_NAME$
3 $IMPLEMENTATION_CLASS_NAME$
4 1
5

6
7 $IMPLEMENTATION_CLASS_NAME$
8 /$DESIRED_UNIQUE_URL$
9

3. Create the implementations – likely as POJOs denoted with the @WebService annotation – and set the corresponding portName for each of them (@WebService(portName=””, …))
4. Deploy and use

1. Define a unique wsdl:port for each implementation

As mentioned, it’s necessary to define a unique wsdl:port for each implementation.

We define two ports, LearningActivityPort1 and LearningActivityPort2, using the same port type (i.e. the same transport protocol etc.).

LearningActivity.wsdl:
view source
print?
01
02
03 ...
04 ...
05 ...
06 ...
07
08
09
10

11
12
13

14

15

2. Define a servlet and servlet mapping for each implementation

Next we need to declare each of the webservice implementation classes as a servlet and define a servlet mapping to assign a unique URL to that implementation as described in WAS help:
web.xml:
view source
print?
01
02
05 pokusWeb4was7
06
07
08 LearningActivityHttpBindingImpl
09 example.LearningActivityHttpBindingImpl
10 1
11

12
13 LearningActivityHttpBindingImpl
14 /LearningActivityJaxbService
15

16
17
18 LearningActivityRawXmlServiceImpl
19 example.LearningActivityRawXmlServiceImpl
20 1
21

22
23 LearningActivityRawXmlServiceImpl
24 /LearningActivityRawXmlService
25

26
27 ...
28


When deployed, the two implementation will be thus available under http://localhost:9080/pokusWeb4was7/LearningActivityHttpService and http://localhost:9080/pokusWeb4was7/LearningActivityRawXmlService.
3. Create each implementation linking it to its port name

Finally we write the two implementation, each being assigned to a different port name:
example.LearningActivityHttpBindingImpl:
view source
print?
1 @javax.jws.WebService (serviceName="LearningActivityHttpService", portName="LearningActivityPort1")
2 public class LearningActivityHttpBindingImpl{
3
4 public TransactionResponseMessage updateLearningActivity(LearningActivityMessage learningActivityMsg) {
5 //...
6 return response;
7 }
8 }

example.LearningActivityRawXmlServiceImpl:
view source
print?
1 @javax.jws.WebService (serviceName="LearningActivityHttpService", portName="LearningActivityPort2")
2 public class LearningActivityRawXmlServiceImpl{
3
4 public TransactionResponseMessage updateLearningActivity(LearningActivityMessage learningActivityMsg) {
5 //...
6 return response;
7 }
8 }
Closing notes

Notice that with JAX-WS

* You don’t need webservice.xml – all the necessary information is (may be) provided via annotations
* You don’t need to declare the web services in web.xml unless you need some special configuration (as we do here)

More Here


Courtesy:http://theholyjava.wordpress.com/2010/12/29/tip-multiple-webservice-implementation-classes-available-at-the-same-time-under-was7/

0 comments:

Post a Comment