|Home > Documentation > User's guide > Sample Applications > jaxws-calculator - Simple Web Service with JAX-WS|
|inventory - Simple Database Access Application||Sample Applications||jms-mdb - JMS and MDB Sample Application|
The sample application referred in this article is a simple calculator which performs addition of two integers. The web service is exposed as a Servlet in the Geronimo application server.
Two clients are provided: a jsp page and a non-javaee client.
The Calculator interface defines the Service Endpoint Interface (SEI) for the Web Service.
The 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.
The 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. In this sample, while not required to implement the web service, it is required to provide the service-ref used by the jsp client.
The geronimo plan has no information for the web service but does specify more information for the service-ref for the jsp client. For tomcat, the plan can be located after building the project in jaxws-calculator/jaxws-calculator-tomcat/target/resources/META-INF/plan.xml. For Jetty, the plan can be located after building the project in jaxws-calculator/jaxws-calculator-jetty/target/resources/META-INF/plan.xml.
You could also deploy the jaxws-calculator-war\target\jaxws-calculator-war-version.war file without a plan,
use the steps below:
Update the "soap:address location" value in the CalculatorService.wsdl to refect the correct version
of the jaxws-calculator-war module, for example
Rebuild the sample and deploy the war.
The following WSDL file describes the Web Service:
In J2EE version 1.4, wsdl file was required to describe the Web Service. In Java EE 5 wsdl file is optional. It can be generated at deployment time by the Geronimo server if CalculatorService.wsdl is not provided with the sample.
In 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.
The add.jsp is a basic client for the CalculatorService Web Service.
The add.jsp looks up a Web Service reference in the JNDI tree. The Web Service reference must first be added the web.xml file.
Resource injection in JSP
Since the resource injection is not supported in JSPs the service-ref must be added explicitly to the web.xml file.
To test this sample service using the add.jsp (http://localhost:8080/jaxws-calculator/) 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:
Command line client CalculatorClient.java is not currently working yet.