In a discussion on interoperability of modern day enterprise applications, Web Services naturally joins the party. Web Service technologies provides J2EE with an opportunity to become truly inter operable with any other system. This is because, Web service technologies are platform-agnostic; in other words, the medium used to communicate is not specific to any combination of programming language, operating system, and hardware.

After reading this article you should be able to deploy web services in the form of servlets in Apache Geronimo and access them with different sorts of clients. This will be a good starting point to web services in the Geronimo server and to getting familiar with cumbersome JAX-RPC technologies.

This article is organized into the following sections : -

Overview of Web Services Features in Geronimo

According to J2EE 1.4 standard there are several options for consuming web services :

  1. A servlet may act as a Web service.
  2. A session bean may act as a Web service.
  3. Any J2EE component may act as a Web service client, using a reference to an external Web service.

Apache Geronimo supports JAX-RPC based Web services according to J2EE 1.4 standard. This means that a Web service application developed for the Geronimo should run on any application server. But JAX-RPC is a technology that is cumbersome and difficult to deal with.

Application Overview

The sample application referred in this article is a simple calculator which performs addition of two integers. The client application referred here is not a J2EE application, which will call a web service to carry out application functionality. Web service is exposed as a servlet in the Geronimo application server.

The following figure illustrates overview of calculator application :

The Web services deployed in the server uses CalculatorService interface as service end point interface. The important thing in this interface is it extends java.rmi.Remote interface and throws java.rmi.RemoteException from exposed methods.
public interface CalculatorService extends java.rmi.Remote
   public int addition( int x,int y ) throws java.rmi.RemoteException;

The service implementation class for the web service is CalculatorServiceServlet. It implements all the methods in the service end point interface. This class will be exposed as a servlet in the web.xml file eventhough it is not necessary to extend javax.servlet.Servlet class.
public class CalculatorServiceServlet {	
	public int addition(int x, int y){
		return x + y;
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:calc="urn:geronimo-samples" 

Note the dependencies section of the geronimo-web.xml file. Those dependencies are mandotory to deploy web services in your web archive.

<web-app xmlns="" xmlns:naming="">
  <dep:environment xmlns:dep="">

To deploy a JAX-RPC based web service, three additional configuration files have to be added into your archive. Those are WSDL file , jaxrpc-mapping file and web service description file. Those configuration files can be found under the config/servlet folder of the application.

WSDL file describes about the web service as given in the below :

<?xml version="1.0" encoding="UTF-8"?>

<definitions name="CalculatorServiceServlet" targetNamespace="urn:geronimo-samples" xmlns:tns="urn:geronimo-samples"
 xmlns="" xmlns:xsd="" 
  <message name="CalculatorService_addition">
    <part name="int_1" type="xsd:int"/>
    <part name="int_2" type="xsd:int"/>
  <message name="CalculatorService_additionResponse">
    <part name="result" type="xsd:int"/>
  <portType name="CalculatorService">
    <operation name="addition" parameterOrder="int_1 int_2">
      <input message="tns:CalculatorService_addition"/>
      <output message="tns:CalculatorService_additionResponse"/>
  <binding name="CalculatorServiceBinding" type="tns:CalculatorService">
    <soap:binding transport="" style="rpc"/>
    <operation name="addition">
      <soap:operation soapAction=""/>
        <soap:body encodingStyle="" use="encoded"
        <soap:body encodingStyle="" use="encoded"
  <service name="CalculatorServiceServlet">
    <port name="CalculatorServicePort" binding="tns:CalculatorServiceBinding">
      <soap:address location="REPLACE_WITH_ACTUAL_URL"/>

jaxrpc-mapping file will map the information with service implementation.

<?xml version="1.0" encoding="UTF-8"?>
<java-wsdl-mapping xmlns="" xmlns:xsi="" 
version="1.1" xsi:schemaLocation="">
    <wsdl-service-name xmlns:serviceNS="urn:geronimo-samples">serviceNS:CalculatorServiceServlet</wsdl-service-name>
    <wsdl-port-type xmlns:portTypeNS="urn:geronimo-samples">portTypeNS:CalculatorService</wsdl-port-type>
    <wsdl-binding xmlns:bindingNS="urn:geronimo-samples">bindingNS:CalculatorServiceBinding</wsdl-binding>
          <wsdl-message xmlns:wsdlMsgNS="urn:geronimo-samples">wsdlMsgNS:CalculatorService_addition</wsdl-message>
          <wsdl-message xmlns:wsdlMsgNS="urn:geronimo-samples">wsdlMsgNS:CalculatorService_addition</wsdl-message>
        <wsdl-message xmlns:wsdlMsgNS="urn:geronimo-samples">wsdlMsgNS:CalculatorService_additionResponse</wsdl-message>

webservices.xml file gives the locations of WSDL and jaxrpc-mapping files to services. The developer needs to have a good understanding of this file than the others given above.

<?xml version="1.0" encoding="UTF-8"?>
<webservices xmlns="" version="1.1">

How to access the Web service deployed in the server in tool independent manner? file demonstrates how to achieve this function.
String urlstr   = "http://localhost:8080/Calculator/calculator?wsdl";

URL url =  new URL(urlstr);

QName qname = new QName("urn:geronimo-samples","CalculatorServiceServlet");

ServiceFactory factory = ServiceFactory.newInstance();
Service  service = factory.createService(url, qname);
CalculatorService calc = (CalculatorService)service.getPort(CalculatorService.class);
int sum = calc.addition(x, y);
System.out.println("Sum of "+x+" and "+y+" is "+sum);

Tools used

The tools used for developing and building the Calculator sample application are:

Java Web Services Developer Kit

The Java Web Services Developer Pack (Java WSDP) is used for simplified development of secure and interoperable Web services applications. The Java WSDP is an integrated toolkit for developing, building, testing, and deploying web services, as well as web and XML-based applications. WSDP has been used to generate jaxrpc-mapping and WSDL files for the Calculator application. WSDP can be downloaded from the following URL:


The Eclipse IDE was used for development of the sample application. This is an extremely powerful and popular open source development tool. Integration plug-ins are available for Geronimo. Eclipse can be downloaded from the following URL:

Apache Ant

Ant is a pure Java build tool. It is used for building the Calculator application. Ant can be downloaded from the following URL:

Back to Top

Configuring, Building and Deploying Sample Application

Download the Calculator application from the following link:

After extracting the zip file, the Calculator directory is created.


Calculator application comes with an Ant script to help users to build from source code. It has to be properly configured before using it to build from source. file in the config directory has to be modified according to your environment. Set the correct path to the <geronimo_home> directory.

This build script depends on Geronimo 1.1.1. Also make sure to use "/" as you directory separator in Windows environment when you are setting the <geronimo_home> directory.


Compile Source Code

Use a command prompt and navigate to the Calculator directory and just give ant compile-web command to build. It will compile the source code into the Calculator/releases/war folder. From these compiled classes we are going to create jaxrpc-mapping and WSDL.

Generate WSDL and jaxrpc-mapping files

We have tested this application with Java WSDP 2.0 and it needs JDK 1.5

If you are not happy with given configuration files in Calculator/config/servlet and want to do some experiments, use the Java WSDP to generate jaxrpc-mapping and WSDL files. Follow these steps to generate those files.

  1. Copy Calculator/config/servlet/config-interface.xml to the WSDP_HOME/jaxrpc/bin.
  2. Create a folder called build under WSDP_HOME/jaxrpc/bin and copy classes folder from Calculator/releases/ear/war/classes.
  3. From command prompt issue the following command in WSDP_HOME/jaxrpc/bin.
    ./ -define -mapping build/jaxrpc-mapping.xml -d build -nd build -classpath build config-interface.xml
    wscompile -define -mapping build/jaxrpc-mapping.xml -d build -nd build -classpath build config-interface.xml
  4. Previous step will generate both WSDL and jaxrpc-mapping file in the WSDP_HOME/jaxrpc/bin/build folder. The next step is to edit jaxrpc-mapping.xml file according to our services. Change the service-interface to org.apache.geronimo.samples.calc.CalculatorService.
  5. Now copy those files to the Calculator/config/servlet folder.
  6. Remove the build file from WSDP_HOME/jaxrpc/bin.

Create WAR file

To create WAR file use ant command while you are in the Calculator folder, from command prompt. This will create Calculator.war file under the Calculator/releases folder.


Deploying sample application is pretty straight forward, since we are going to using Geronimo Console.

  1. Scroll to Deploy New from the Console Navigation panel.
  2. Load Calculator.war from Calculator/releases folder in to the Archive input box.
  3. Press Install button to deploy application in the server.

Testing of the Sample Application

To test this sample application we are going to run the CalculatorClient application as given below.

ant run-client -Dval1=<num1> -Dval2=<num2>

lsf@lsf-laptop:~/workspace/Calculator$ ant run-client -Dval1=1 -Dval2=12
Buildfile: build.xml
     [java] Working directory ignored when same JVM is used.
     [java] Sum of 1 and 12 is 13


This article has shown, how to deploy a simple web service in J2EE specific manner. The highlights of this article :

  • As a J2EE 1.4 certified application server Apache Geronimo supports JAX-RPC based Web service deployment.
  • Deploy simple Web service in Geronimo as a servlet.
  • Generate Web service related configuration files from Java WSDP.
  • Access a deployed Web service from a client other than J2EE.
  • No labels