This tutorial takes you through the steps that are required to consume Yahoo! REST Web Services. Although there isn't much for this tutorial to deal with any Geronimacal Issues, this clearly demonstrates the ease of developing or consuming REST service without any external tools compared to SOAP Web Services.
We will explore two REST services from many that are exposed by Yahoo! which are Yahoo! Search and Yahoo! Maps. You might need an appid to query the results from Yahoo Server. For the time being I have added my appid in the code wherever needed.
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 steps required are:
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-yahoo 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-yahoo.
- Click Finish
Developing the Web based Client
- Right Click the jaxws-rest-yahoo, 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 maps.jsp
- Add the following code to maps.jsp
- Now we need to create the two servlets which will handle the requests generated by user.
- Right click again and add a Servlet named ConverterHandler
- Add the following code to ConverterHandler.java
- Right click again and add a Servlet named MapHandler
- Add the following code to MapHandler.java
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
- Deploy and test our custom built Yahoo!