Application Overview application
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. It is a regular Java client which will call a web service to carry out the application functionality. Web service is exposed as a Servlet in the Geronimo application server.
Service implementation
The Calculator interface defines the Service Endpoint Interface (SEI) for the Web Service.
javasolidCalculator.javaThe CalculatorService class implements the Web Service business logic. It implements all the methods defined in the SEI. The class does not need to implement the Calculator interface but must reference it through the @WebService.endpointInterface annotation. This class will be exposed as a Servlet through web.xml file even though it does not extend the javax.servlet.Servlet class.
The context variable marked with the @Resource annotation will be injected at runtime. The WebServiceContext can be used to obtain the message context and security information relative to the call.
The web.xml descriptor is used to deploy the Web Service.
xmlsolidweb.xmlThe web.xml descriptor is not necessary for simple JAX-WS web service deployments. If the web.xml descriptor is not provided, it will be automatically generated during deployment.
The geronimo-web.xml descriptor is optional but it is used in this sample to specify the module name. Information about the project (e.g. module's unique identification, any dependencies) is described inside the <environment> tag. In this case, there are no dependencies so they do not need to be listed. However, it is a good idea to give this module some sort of unique identification, so that it can later be referenced by some other deployable application.
xmlsolidgeronimo-web.xmlThe following WSDL file describes the Web Service:
xmlsolidCalculatorService.wsdlIn J2EE version 1.4, the webservices.xml file was also necessary to describe the Web Service. In Java EE 5 that file is optional and is not required in this example.
JSP-based JAX-WS client
The add.jsp is a basic client for the CalculatorService Web Service.
javasolidadd.jspThe add.jsp looks up a Web Service reference in the JNDI tree. The Web Service reference must first be added the web.xml file.
xmlsolidweb.xmlSince the resource injection is not supported in JSPs the service-ref must be added explicitly to the web.xml file.
Building and Deploying Sample Application configure
Checkout the sample source code from SVN:
svn checkout http://svn.apache.org/repos/asf/geronimo/samples/trunk/samples/jaxws-calculator calculator
The source code will be checked out into the calculator/ directory. This sample code code lives in calculator/jaxws-calculator-war/ directory.
Required Tools
The tools used for developing and building the Calculator sample application are:
Apache Maven 2.0.x
Apache Maven is used for building the Calculator application.
Building
Compile Source Code
From command prompt execute the following command in the calculator/jaxws-calculator-war/ folder:
mvn install
After the code is successfully compiled a jaxws-calculator-war-2.0-SNAPSHOT.war file will be created in the target/ subfolder.
Deploying
Deploy the jaxws-calculator-war-2.0-SNAPSHOT.war using the Geronimo Console (http://localhost:8080/console):
- Scroll to Deploy New from the Console Navigation panel.
- Load jaxws-calculator-war-2.0-SNAPSHOT.war from calculator/jaxws-calculator-war/target/ folder in to the Archive input box.
- Press Install button to deploy application in the server.
Testing of the Sample testing
To test this sample service use the add.jsp (http://localhost:8080/jaxws-calculator/add.jsp) to invoke the Web Service. Once the JSP page loads type in two values to add and press the Add button. The result of the addition should show up below. For example: