Lets Talk About Technologies

Menu

RESTful Webservices with Jersey

I have discussed my earlier article about architectural consideration on RESTful system for distributed environment. This article we are going to discuss how to build RESTful web services with Jersey and Apache Tomcat.

This tutorial explains how to develop RESTful web services in Java with the Tomcat 6, Eclipse and Jersey a JAX-RS (JSR 311) reference implementation.

In a nutshell a RESTful web service is a communication between machines using HTTP on REST principles which have following key points:

Each resource represents unique URI to communicate over HTTP protocols

Request and Response supported by JSON, XML and various MIME type such as image, byte stream etc.

JAX-RS

JAX-RS is an annotation-based API for implementing RESTful web services, based on HTTP, in Java. Essentially, classes and methods are annotated with information that enables a runtime to expose them as resources. A runtime that implements JAX-RS mediates between the HTTP protocol and the Java classes, taking into account URIs, requested , content types, and HTTP methods.

Jersey framework implemented JSR-RS(JSR-311) reference APIs. In addition to Jersey various other implementation are available such as Retlet, JBOSS RESTeasy, Apache CXF etc.

Jersey:

Jersey contains following major parts:

Core Server: To build RESTful web services based on annotation which include key libraries such as : jersey-core.jar, jersey-server.jar, jsr311-api.jar, asm.jar

Resources are anything that are addressable and manipulated over the web . Jersey resources are plain java object (POJO) with annotation @Path and will be manipulated by HTTP methods POST, GET,PUT and DELETE. A resource also has sub resources. In the sample application UsersResource for Users java bean is Resources. Users is simple POJO with attributes ‘name’ and ‘password’

Jersey provide client to test the RESTful web services whic help to communicate with server and test the services. The client library is a generic implementation that can cooperate with any HTTP/HTTPS-based Web service.

6 thoughts on “RESTful Webservices with Jersey”

Hi just wanted to give you a quick heads up and let you know a few of the pictures aren’t
loading properly. I’m not sure why but I think its a linking issue.
I’ve tried it in two different web browsers and both show
the same outcome.

Thank you for any other informative website.
Where else may I get that kind of info written in such an ideal means?
I have a project that I am simply now operating on, and I have been on the look out for
such info.

I see the example of the client which tests the service in most such tutorials. I on the other hand am trying to write a Java swing application that will interact with the rest service. So I got the service part running (meaning i can hit the URL and i am able to get the xml response) but now how do I use jersey to make a call to that url and interpret the xml and parse it into objects to show it to the end-user? I am not able to find a way to do that. Can you please share some thoughts on this?
Thanks