Lesson 2: Creating and testing the web service
After you have created a JAX-RS enabled project, you can download the Java™ files used by the application and test the web service.
Create a JAX-RS web service
Procedure
- Download the project which contains the Java classes needed for the application.
- In your web project, create a package called com.test (right-click Java Resources > src and select New > Package). Import the following
classes from the downloaded project into the package:
- AddressBook.java
- AddressBookApplication.java
- Open WebContent/WEB-INF/web.xml. In the
Design view, select the Servlet (JAX-RS Servlet) and click Add and
add an Initialization parameter to the JAX-RS servlet, leaving the
name and value fields empty. Save web.xml ignoring
any errors that might be displayed.
- In the Problems view, right-click the param-name warning and select Quick Fix. Select to browse for an existing sub-class, and select the AddressBookApplication.
- Save web.xml.
Test the JAX-RS web service
Procedure
- In the Servers view, right-click your server and select Add and Remove, and add the JAX-RS EAR to the server. Restart the server.
- To retrieve all addresses in the Address Book application,
open a Web browser and enter the following URL: http://localhost:<default_host_port>/<application_name>/jaxrs/addresses For example, following the naming convention used in this tutorial
and the default port, http://localhost:9080/JAXRS/jaxrs/addressesNote: You can determine the default host port name in the WebSphere Application Server Admin Console server configuration tab.
- Enter the following URL: http://localhost:<default_host_port>/<application_name>/jaxrs/addresses/<address index> The address index is a number between 0 and 5 which represent the 6 addresses listed in AddressBook.java. The address assigned to that index value will display.

