Consuming Yahoo! REST Web Services
Skip to end of metadata
Go to start of metadata

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.

Icon

Yahoo! is one company which is very much in the support of RESTful Web Services. Many of the Yahoo! API's and Services are REST. Some examples are Search, Maps, Mail, Flickr, del.ico.us etc

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
index.jsp
  • Right click again and add another jsp named maps.jsp

  • Add the following code to maps.jsp
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
SearchHandler.java
  • Right click again and add a Servlet named MapHandler

  • Add the following code to MapHandler.java
MapHandler.java
Icon

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

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
geronimo-web.xml
  • Deploy and test our custom built Yahoo!
Labels
  • No labels
  1. 1. Instructions to create SearchHandler Servlet should be as follows:

    •Right click again and add a Servlet named ConverterHandler SearchHandler

    •Add the following code to ConverterHandler.java SearchHandler.java

    2. Adding external .jar libraries to the project

    •Select the top-level project node jaxws-rest-yahoo. Select Project -> Properties from the menu.

    •In the Java Build Path section select Libraries and click on Add External JARs...

    •Select commons-codec-1.3.jar and commons-httpclient-3.0.1.jar from the paths mentioned.