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
/BookstoreGET
/countBookstore GET
/timeBookstoreGET
/items/{itemid}Book, CDGET
/items/{itemid}/tracks/{num}TrackGET

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.

Comments:

cvbcv

Posted by guest on April 08, 2008 at 08:39 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jakub Podlesak

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today