• REST
    September 17, 2007

RESTful Web Services On Glassfish

Recently Jersey module become available on GlassFish Update Center. It comes along with several examples, which use GlassFish as a web container.
The examples show how to build RESTful web services using Java.
If you want to see such web services in action and find out how to implement them, the fastest way is probably to
This entry will introduce one of the examples and I plan to write about the others in blog entries to come.

Bookstore example

After installing Jersey module, the Bookstore example should be available at $AS_HOME/jersey/examples/Bookstore directory.
To run the example you can do the following:
Change dir:

% cd $AS_HOME/jersey/examples/Bookstore

Build the example by running ant bundled within GlassFish:

% $AS_HOME/lib/ant/bin/ant

Start default GlassFish domain via command line interface.

% $AS_HOME/bin/asadmin start-domain

Deploy the sample:

% $AS_HOME/bin/asadmin deploy dist/Bookstore.war

The whole example consists of a bookstore with CDs and books. CDs have tracks associated with them. To model the bookstore in RESTful world, the example introduces bookstore, CD, book and track resources.
Mapping of URIs to individual resources is shown in the following table:
URI pathResource classHTTP methods
/countBookstore GET
/items/{itemid}Book, CDGET

So if you open your web browser and navigate to http://localhost:8080/Bookstore,
you should see something like this:

which is a HTML representation of the bookstore resource.
It provides links to it's contents, so you can also ask for (and HTTP GET:-) representations
of a particular CD item and one of it's tracks:

Bookstore example provides only read-only access to it's resources but it gives you a very good chance to see
how to
  • implement container-containee relationship
  • and how to use JSP views for your resource representations

Jersey module comes along with source code, so there is nothing to prevent you from playing and experimenting with the Bookstore example.

Join the discussion

Comments ( 1 )
  • guest Tuesday, April 8, 2008


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.