DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Understanding Data Compaction in 3 Minutes
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • DevOps vs. DevSecOps: The Debate
  • How AI Will Change Agile Project Management

Trending

  • Understanding Data Compaction in 3 Minutes
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • DevOps vs. DevSecOps: The Debate
  • How AI Will Change Agile Project Management

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

Jakub Holý user avatar by
Jakub Holý
·
Jan. 06, 11 · Interview
Like (0)
Save
Tweet
Share
14.74K 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.

Trending

  • Understanding Data Compaction in 3 Minutes
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • DevOps vs. DevSecOps: The Debate
  • How AI Will Change Agile Project Management

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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

Let's be friends: