Using the IBM JAX-RS Hello World sample

The product provides a Hello World sample that demonstrates a simple Representational State Transfer (REST) application using the IBM® Java API for RESTful Web Services (JAX-RS) implementation.

Before you begin

The following table lists the required prerequisites for the Hello World sample.

Product prerequisite Version
Java Technology Edition 5.0 or 6.0
Java 2 Platform, Enterprise Edition (J2EE) 1.4 or Java Enterprise Edition 5 (Java EE) application server WebSphere® Application Server Version 6.1.0.x 

About this task

The Hello World sample application demonstrates a simple REST application using the IBM JAX-RS implementation. The sample includes two independent Web archive (WAR) files. One Web module uses the IBM JAX-RS servlet to service requests while the other module uses the IBM JAX-RS filter to service requests. While both Web modules provide simple Hello World services, the two modules demonstrate the differences using the JAX-RS servlet and the filter. You can choose to use either the servlet or the filter when developing your RESTful services. The source code for the sample is packaged with the enterprise archive (EAR) application.

Also provided with the Hello World sample is a stand-alone Java client. This client is a simple client that posts and retrieves information from the Hello World service. The source code is packaged with the JAR file.

Limitations
  • The IBM JAX-RS Hello World sample application is not intended for deployment to production servers. It is for development and educational purposes only.
  • All source code for the sample servlets and Web pages is provided as is for you to use, copy, and modify without royalty payment when you develop applications that run with WebSphere software. You can use the sample code either for your own internal use or for redistribution as part of an application, or in your products.

By default, you can install the EAR application with minimal configuration. A Web module that uses the IBM JAX-RS servlet has been preconfigured with a context root of /restservlet. A Web module that uses the IBM JAX-RS filter has been preconfigured with a context root of /restfilter.

During the installation of the Feature Pack for Web 2.0, you can choose to install the IBM JAX-RS samples. Use the following instructions to install the sample outside of the product installation process.

Procedure

  1. Locate the ibm-sample-helloworld-server.ear file in the <install_root>/web2mobilefep_1.1/samples directory. The <install_root> specifies the directory where the Feature Pack for Web 2.0 is installed on WebSphere Application Server.
  2. Log in to the administrative console for the application server.
  3. Click Applications > Enterprise Application in the console navigation tree.
  4. Browse the file system to locate the Guest book sample application that you located in step 1 and click Next.
  5. Select the Prompt me only when additional information is required option.
  6. Expand Choose to generate default bindings and mappings and select Generate Default bindings.
  7. Click Next and take the default installation options.
  8. Click Next and take the default Map Modules to Servers options.
  9. Click Next and take the default Map virtual hosts for Web modules options.
  10. Click Next and take the defaults on the Summary page.
  11. On the Summary panel, click Finish.
  12. Click OK and then click Save to save the configuration.

Results

You have completed the installation of the Hello World sample.

You can now begin using Hello World sample, which demonstrates the configuration of services using the IBM JAX-RS server runtime and the use of a stand-alone Apache Wink client.

What to do next

Contents of the Hello World sample

There are two separate Web modules in the sample application. One of the Web modules uses the JAX-RS servlet and the other uses the JAX-RS filter. Depending on the needs of your test application, you can choose to use either the servlet or the filter. The configuration differences between the two Web modules are primarily in the web.xml file.

Both Web modules expose a simple resource with a JAX-RS @Path value of helloworld. In this sample application, the resource representation is a plain text string. You can retrieve the representation of the resource by issuing an HTTP GET method to the appropriate URL. You can also use an HTTP PUT or POST method to change the representation of the resource and use an HTTP DELETE method to remove the representation.

The servlet module

The servlet version of the Web module for this sample has a context root value of restservlet. In the web.xml file for the Web module, the URL pattern is restapi/*. Therefore, all resources in the Web module have a URL prefix of http://<hostname>:<port>/restservlet/restapi.

If the installation of this product is completed on a local machine, issuing an HTTP GET command to http://localhost:9080/restservlet/restapi/helloworld using either the sample stand-alone Java client or a Web browser, returns a simple string value.

The filter module

The filter version of the Web module for this sample has a context root value of restfilter. In the web.xml file for the Web module, the URL pattern is /*. Therefore, all resources in the Web module have a URL prefix of http://<hostname>:<port>/restfilter/. For more information, see the configuring the web.xml filter documentation for details on the differences between the servlet and filter.

The stand-alone Java client
The stand-alone Java client is packaged in its own JAR file, ibm-sample-helloworld-client.jar. You must place the following JAR files in the same directory as the sample client application JAR file:
  • slf4j-jdk14.jar
  • slf4j-api.jar
  • jsr311-api.jar
  • ibm-wink-jaxrs.jar
You can invoke the stand-alone client by issuing the following command:
java -jar ibm-sample-helloworld-client.jar
The stand-alone client issues requests to the service.



In this information ...


Related concepts

IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Sep 6, 2012 5:50:55 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v610webmob&product=was-nd-mp&topic=twbs_jaxrs_samples_helloworld
File name: twbs_jaxrs_samples_helloworld.html