DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Tip: Multiple Web Service Implementation Classes Available at the Same Time Under WAS7

Tip: Multiple Web Service Implementation Classes Available at the Same Time Under WAS7

Jakub Holý user avatar by
Jakub Holý
·
Jan. 06, 11 · Java Zone · Interview
Like (0)
Save
Tweet
14.39K Views

Join the DZone community and get the full member experience.

Join For Free

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

  1. For each alternative implementation, add <wsdl:port> with a unique name under the <wsdl:service> 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:
<servlet id="$IMPLEMENTATION_CLASS_NAME$">
<servlet-name>$IMPLEMENTATION_CLASS_NAME$</servlet-name>
<servlet-class>$IMPLEMENTATION_CLASS_NAME$</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>$IMPLEMENTATION_CLASS_NAME$</servlet-name>
<url-pattern>/$DESIRED_UNIQUE_URL$</url-pattern>
</servlet-mapping>
  1. Create the implementations – likely as POJOs denoted with the @WebService annotation – and set the corresponding portName for each of them (@WebService(portName=”<unique port name>”, …))
  2. 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:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions ...>
<wsdl:types>...</wsdl:types>
<wsdl:message ...>...</wsdl:message>
<wsdl:portType name="DefaultPortType">...</wsdl:portType>
<wsdl:binding name="LearningActivityHttpBinding" type=...>...</wsdl:binding>
<wsdl:service name="LearningActivityHttpService">
<wsdl:port binding="tns:LearningActivityHttpBinding" name="LearningActivityPort1">
<soap:address location="http://example.com/myApp/LearningActivityHttpService" />
</wsdl:port>
<wsdl:port binding="tns:LearningActivityHttpBinding" name="LearningActivityPort2">
<soap:address location="http://example.com/myApp/LearningActivityRawXmlService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

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:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>pokusWeb4was7</display-name>

<servlet id="LearningActivityHttpBindingImpl">
<servlet-name>LearningActivityHttpBindingImpl</servlet-name>
<servlet-class>example.LearningActivityHttpBindingImpl</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>LearningActivityHttpBindingImpl</servlet-name>
<url-pattern>/LearningActivityJaxbService</url-pattern>
</servlet-mapping>

<servlet id="LearningActivityRawXmlServiceImpl">
<servlet-name>LearningActivityRawXmlServiceImpl</servlet-name>
<servlet-class>example.LearningActivityRawXmlServiceImpl</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>LearningActivityRawXmlServiceImpl</servlet-name>
<url-pattern>/LearningActivityRawXmlService</url-pattern>
</servlet-mapping>

<welcome-file-list>...</welcome-file-list>
</web-app>

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:

@javax.jws.WebService (serviceName="LearningActivityHttpService", portName="LearningActivityPort1")
public class LearningActivityHttpBindingImpl{

public TransactionResponseMessage updateLearningActivity(LearningActivityMessage learningActivityMsg) {
//...
return response;
}
}

example.LearningActivityRawXmlServiceImpl:

@javax.jws.WebService (serviceName="LearningActivityHttpService", portName="LearningActivityPort2")
public class LearningActivityRawXmlServiceImpl{

public TransactionResponseMessage updateLearningActivity(LearningActivityMessage learningActivityMsg) {
//...
return response;
}
}

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)

 

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

Implementation Web Service

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Build a Simple CLI With Oclif
  • Blocking Ads on Your Network Using Raspberry Pi 3 + Fedora + Pi-hole
  • Exhaustive JUNIT5 Testing with Combinations, Permutations, and Products
  • How To Evaluate Software Quality Assurance Success: KPIs, SLAs, Release Cycles, and Costs

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo