Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

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

...

Details on installing Eclipse are provided in the Development environment section.

...

...

...

This tutorial assumes that you have completed the Developing a simple RESTful Service tutorial. Here we will try to develop the client for the web service deployed in the above mentioned tutorial.

This tutorial will take you through the following steps:

...

Create a Dynamic Web Project to consume the Web Service

...

  • 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

...

...

...

Here the servlet might notify that some imports are not resolved. We need to add two external jar files to resolve these errors.
The jar files that needed to be added in the build path are:
commons-codec-1.3.jar - <GERONIMO_INSTALL_DIR>\repository\commons-codec\commons-codec\1.3\commons-codec-1.3.jar
commons-httpclient-3.0.1.jar - <GERONIMO_INSTALL_DIR>\repository\commons-httpclient\commons-httpclient\3.0.1\commons-httpclient-3.0.1.jar

  • 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. Infotitle XPath Processing

      XPath (XML Path Language) is a language for selecting nodes from an XML document with very advanced features.

      Our response message sent by web service may look like this:

      Code Blocktitle

      response.xml <return> <dollarToRupeesResponse>933.34</dollarToRupeesResponse> <rupeesToEuroResponse>933.34</rupeesToEuroResponse> </return>

      We will first try to get the NodeList present between <return> elements, Then we evaluate each child node to get the results.

This concludes the development section of our web based client.

...

  • 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 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.


...


...

...

The code for testing the RESTful service via POST method hasn't been added to the ConverterHandler.
A sample post file might look like this

...

...

This completes the development of a simple RESTful client that consumes a RESTful Web Service that is already deployed on the server.