Category Archives: Tomcat and Application Servers

Posts on Application servers, Tomcat server …

Developping and deploying webservice onto Tomcat

Deploying Webservices onto Tomcat is possible with the metro library.

Below is concise description on how to achieve that.

Configuration
Add to your web.xml the following servlet configuration

<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
    <servlet-name>service</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>service</servlet-name>
    <url-pattern>/MyService/*</url-pattern>
</servlet-mapping>

Here we add the metro listener on startup WSServletContextListener to initialize the Webservice context. We declare the Servlet (metro servlet) WSServlet and bind it to the context MyService (the context MyService name here is arbitrary).

To finalize configuration, create next to your web.xml (generally in the WEB-INF folder), the sun-jaxws.xml file with the following content

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
    <endpoint name="service" implementation="com.ichir.projects.services.ServiceImpl" url-pattern="/MyService" />
</endpoint

As you can see, in this file, we bind the Webservice context (MyService) to the webservice implementation class com.ichir.projects.services.ServiceImpl.

The webservice implementation class (a simple Calculator/Summer) is a regular @Webservice annotated class

package com.ichir.projects.services;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public class ServiceImpl {
	public int calculate(@WebParam(name="a") int arg0, @WebParam(name="b") int arg1) {
		return arg0 + arg1;
	}
}

Deploy your webservice onto Tomcat and enjoy!

Downloads

References

Context

  • Maven 2 or higher
  • Servlet API 2.5
  • Metro library 2.2.x
Advertisements

Java WS webservices, IBM Websphere and Eclipse

IBM Websphere, unlike some other Application servers, needs some more configuration files in order to be able to deploy an Java WS annotation based Webservice web (.war) application:

  • ibm-web-bnd.xml
  • ibm-web-ext.xml
  • web_merged.xml

Their content for a basic application deployment (i.e. deploying on the default virtual host and with no security configuration) is quite basic:

web_merged.xml
web_merged.xml
ibm-web-ext.xml
ibm-web-ext.xml
ibm-web-bnd.xml
ibm-web-bnd.xml
  • These files are automatically created for you if you use MyEclipse to develop your webservices web application.
  • I’ve never tried it, but I was told that IBM RAD also creates these files for you.

However, if you use Eclipse, you get in troubles ! You developed your webservices web application using @Webservice, @SOAPBinding, … Java WS annotations; you deployed you application on Glassfish for example, everything goes right. However once you deploy on IBM Websphere Application server (WAS) … BIG FAIL! you do not see your webservices published (no WSDL generated nor published)!

Don’t panic, the solution exists and is straight forward! Just copy these files at the root of you WEB-INF folder, along with your web.xml Web application file and your are done ! redeploy your application and you should see now your WSDL generated and published.

Notes

Please refer to IBM website for more documentation on these files and for more advanced configuration features.

I do not provide the sources of the XML files listed above for evident copyright reasons.

This post has been tested using IBM Websphere 7.x and Java WS 2.x

References