RESTful Web Services On Glassfish
By Jakub Podlesak on Sep 17, 2007
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
- download and install GlassFish
- install Jersey module from GlassFish Update Center
- Try out the examples bundled with Jersey
This entry will introduce one of the examples and I plan to write about the others in blog entries to come.
After installing Jersey module, the Bookstore example should be available at
To run the example you can do the following:
% cd $AS_HOME/jersey/examples/Bookstore
Build the example by running ant bundled within GlassFish:
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 path||Resource class||HTTP methods|
So if you open your web browser and navigate to
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
- 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.