Learn to REST using Jersey

Jersey is the open source JAX-RS (JSR 311) Reference Implementation for building RESTful Web services. Paul announced the availability of 0.2.1. This blog entry describe the steps to get started with Jersey and provide useful pointers for further exploration.

  1. Download a stable build from here or the latest binary from here. jersey-xxx-ea.zip is the binary distribution and jersey-snapshot-xxx-ea.zip is a snapshot of the SVN repository.

  2. The bundle comes with all the required binaries (JAR dependencies) and a good set of samples for 0.2.1. Here is a consolidated list:

    HelloWorld This is how everybody starts!
    GlassFishDB Demonstrates how to use JPA to expose the contents of a database table as a RESTful resource.
    JsonFromJaxb Demonstrates how to use JSON representation of JAXB-based resources.
    EntityProvider Demonstrates pluggable entity providers.
    Bookmark Demonstrates how to use JPA in the backend.
    Bookstore Demonstrates how to use ploymorphism with resources and views that are JSP pages.
    OptimisticConcurrency Demonstrates the application of optimistic concurrency to a web resource.
    SimpleAtomServer Simple Atom server that partially conforms to the Atom Publishing Format and Protocol
    SimpleConsole Demonstrates how to use the Lightweight HTTP Server included in Sun's Java SE 6.0 release.
    SimpleJAXWSEndpoint Demonstrates how to use a JAX-WS Endpoint.
    SimpleServlet Demonstrates how to use a Servlet container.
    StorageService Demonstrates a basic in-memory web storage service

    Pick a sample, most likely "Hello World", and then follow the instructions in the main "examples" directory to run the sample.

  3. Here are some other useful pointers:
  4. As Alexis pointed, GlassFish is the preferred platform for deploying Jersey endpoints and NetBeans 6 will soon support Jersey.

Paul explained Why the name Jersey ? - Jersey is a restful place to spend a couple of days vacation. The Yellow jersey or Maillot jaune (the project logo) is worn by the overall leader in Le Tour. With modesty I would like this to be the leading open source project for developing RESTful Web services using plain old Java objects.

And then it could also be Java basEd RESTful Services for You as coined by Sridatta :)

Technorati: jersey jsr311 REST restful glassfish netbeans

Comments:

FYI, here's the link for browsing the source code and SVN checkout information:
https://jersey.dev.java.net/source/browse/jersey/

Posted by Glen on September 06, 2007 at 04:35 AM PDT #

FYI, here's the link for browsing the source code and SVN checkout information:
https://jersey.dev.java.net/source/browse/jersey/

Posted by Glen on September 06, 2007 at 04:44 AM PDT #

Arun, the Hello World sample above is using the Lightweight HTTP Server. I'm not sure how much this server is intended though for serious production use. How can we wrap this sample up into a WAR file for Tomcat or GlassFish? If you know of a link that explains this, great, else this might make a good future TOTD note.

Posted by Glen on September 10, 2007 at 09:15 AM PDT #

Glen, one of the samples listed at http://blogs.sun.com/arungupta/entry/learn_to_rest_using_jersey shows how to deploy a Servlet-based endpoint. Let me know if that does not work and I'll create a TOTD.

Posted by Arun Gupta on September 10, 2007 at 10:15 AM PDT #

Any suggestions for running Bookmark sample using Netbeans&glassfish V3 ?
Many errors can't fix.

Posted by Mark Gu on January 07, 2009 at 05:44 AM PST #

Mark,

Have you tried posting question to users@jersey.dev.java.net ?

Posted by Arun Gupta on January 07, 2009 at 06:00 AM PST #

@Mark Gu: the bookmark exampleworks fine with GFv2. The example uses JPA, and i have not had a chance yet to look at how this works in GFv3. Is this (JPA/GFv3) what you are interested in? If not, there are some more examples, which you might want to look at to see how to develop RESTful web services in Java using Jersey. These examples run fine on GFv3.

Posted by Jakub Podlesak on January 07, 2009 at 05:04 PM PST #

Hi,

Am facing problem while consuming a REST service. Am not getting proper response. Could you help me with the sample code.

Thanks in advance.

Regards
Srinadh

Posted by srinadh on June 19, 2009 at 11:55 PM PDT #

Srinadh, have you tried posting request to users@jersey.dev.java.net ?

-Arun

Posted by Arun Gupta on July 02, 2009 at 03:20 AM PDT #

Arun,

At service level i kept annotation as GET but am trying to place POST request from client application. Now its working fine. REST is really wonderfull. It is reducing lot of overhead. Once concern is how to implement security feature.

Srinadh

Posted by Srinadh on July 03, 2009 at 05:05 PM PDT #

I think this should be:

@Path("/{paramOne}/{paramTwo}")
def getService(@PathParam('paramOne') String paramOne, @PathParam("paramTwo") Long paramTwo, @QueryParam('aquery') Integer aquery)

But I am getting a NFE as paramTwo is being being extracted with the '?'

Can you confirm as I am unable to find any documentation on using the @PathParam & @QueryParam together.

Posted by Duncan on March 08, 2011 at 09:32 PM PST #

Duncan,

I've not used the parameters like these. Can you post your question to users@glassfish.java.net ?

-Arun

Posted by Arun Gupta on March 09, 2011 at 07:09 AM PST #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

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