This tutorial will take you through the steps required in developing, deploying and testing a RESTful Web Service Client in Apache Geronimo for a web services which are already deployed on the server
We will be creating a Web based Client which can access the RESTful web service via GET and POST methods. You can easily create this client without any external tools except that of a server environment.
To run this tutorial, as a minimum you will be required to have installed the following prerequisite software.
- Sun JDK 5.0+ (J2SE 1.5)
- Apache Geronimo 2.x
- Eclipse IDE for Java EE Developers - Europa release
- Geronimo Eclipse Plug-in 2.x
Details on installing Eclipse are provided in the Development environment section.
This tutorial will take you through the following steps:
Create a Dynamic Web Project to consume the Web Service
- From Eclipse main menu, select File->New->Other
- In the New dialog, select Web->Dynamic Web Project and click Next
- Type jaxws-rest-converterclient as the Project Name and click Next
- On the Project Facets page, the default selections are enough.
- Make sure that the check box Generate Deployment Descriptor is selected and click Next
- On the Geronimo Deployment Page modify the Group Id to org.apache.geronimo.samples.jaxws.rest and the Artifact Id to jaxws-rest-converterclient.
- Click Finish
Developing the Web based Client
- Right Click the jaxws-converterclient, and Select New->JSP
- Name the jsp as index.jsp and click Finish
- Add the following code to the index.jsp
- Right click again and add another jsp named post.jsp
- Add the following code to post.jsp
- Right click again and add a Servlet named ConverterHandler
- Add the following code to ConverterHandler.java
- Let us walkthrough the code of ConverterHandler servlet.
- We will create a HttpClient object and GetMethod object for our requestquery. Then we will execute the method on our client object.
- The response after executing the method will be taken as a stream so as to parse the XML elements in response message sent by the Web Service.
- Here we used XPath to process XML response messages sent by web service.
This concludes the development section of our web based client.
Setting Up the Deployment Plan
- As two external jars have been added to the project's build path, One needs to specify them as dependencies so that at runtime application can resolve the classes.
- Expand WebContent/WEB-INF directory and open geronimo-web.xml
- Add the following code to geronimo-web.xml
Deploying and Testing the Web Client
- Right click on the Apache Geronimo Server Runtime present in the servers view and select Add and Remove Projects
- Add jaxws-rest-converterclient to configured projects list and then click Finish
- Wait for some time till the server status changes to Synchronized
- Right click the index.jsp present under WebContent directory of our project and select Run As->Run On Server
- In the popup, check the check box Always use this server when running the project and then click Finish
- Now Eclipse will try to open the jsp in a web browser which shows you a form to enter amount in Dollars.
- Enter any amount and press submit, the jsp should display the result that is returned by the web service.
This completes the development of a simple RESTful client that consumes a RESTful Web Service that is already deployed on the server.