|Home > Documentation > Sample applications > Web services sample application|
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 interoperable 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 :
According to J2EE 1.4 standard there are several options for consuming web services :
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.
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.
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 even though it is not necessary to extend javax.servlet.Servlet class.
Note the dependencies section of the geronimo-web.xml file. Those dependencies are mandatory to deploy web services in your web archive.
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 :
jaxrpc-mapping file will map the information with service implementation.
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.
How to access the Web service deployed in the server in tool independent manner? CalculatorClient.java file demonstrates how to achieve this function.
The tools used for developing and building the Calculator sample application are:
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:
Ant is a pure Java build tool. It is used for building the Calculator application. Ant can be downloaded from the following URL:
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. build.properties file in the config directory has to be modified according to your environment. Set the correct path to the <geronimo_home> directory.
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_home>/releases/war folder. From these compiled classes we are going to create jaxrpc-mapping and WSDL.
If you are not happy with given configuration files in <calculator_home>/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.
./wscompile.sh -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
jaxrpc-mapping.xmlfile according to our services. Change the service-interface to org.apache.geronimo.samples.calc.CalculatorService.
CalculatorServiceServlet.wsdlfiles to the <calculator_home>/config/servlet folder.
To create WAR file use ant command while you are in the <calculator_home> directory, from command prompt. This will create Calculator.war file under the <calculator_home>/releases folder.
Deploying sample application is pretty straight forward, since we are going to using Geronimo Console.
To test this sample application run the CalculatorClient application from the <calculator_home> directory.
ant run-client -Dval1=<num1> -Dval2=<num2>
This article has shown, how to deploy a simple web service in J2EE specific manner. The highlights of this article :