Jersey + Guice + Scala

At Pongr, our RESTful web services are built using Jersey, Guice and Scala (among many other technologies). Here’s a quick post that shows how to set up an example project that uses all three. By the end we’ll be able to declare Guice bindings in our own custom module and have them injected into Jersey…

Dynamically Generating Zip Files in Jersey

We often need to pull a large number of rows from a database table, split those rows up into n groups, and write each group out to a separate text file.  These text files are then processed by another application.  Each text file starts with the number of rows in the file on the first…

URI Extensions in Jersey

Jersey provides an excellent system for easily supporting multiple representations of resources. You use the @Produces annotation to define which formats a resource method supports: In this case clients can obtain the representation of the thing resource in either XML or JSON format (assuming you’ve registered corresponding MessageBodyWriters for the Thing class).  Just by including…

XHTML Resource Representations in Jersey using StringTemplate

Most web services these days use XML and/or JSON as representation formats, mainly because they are simple to create and are easily parseable by other apps.  A less commonly used, but extremely useful format is XHTML.  But wait, that’s for displaying web pages right?  It sure is, but it’s also valid XML.  So if you…

Use Exceptions to Send Error Responses in Jersey

Jersey provides several different ways to send back particular HTTP responses.  While your resource methods can all return Response objects, sometimes it’s more natural to return a domain object if everything goes OK and throw exceptions when errors occur. The WebApplicationException class serves this purpose.  You throw an instance of it in your resource method,…

Override the HTTP Request Method in Jersey

RESTful web services take advantage of all of the HTTP methods including GET, POST, PUT, DELETE, HEAD and OPTIONS.  However, a lot of HTTP libraries (BlackBerry JDE, iPhone SDK, etc) and all browsers only support GET and POST.  There are several ways to get around these deficiencies – in this post I’ll describe two of…

The Top-Level Resource in Jersey

In RESTful Web Services, the authors define three types of resources exposed by a web service: Predefined one-off resources for especially important aspects of the application A resource for every object exposed through the service Resources representing the results of algorithms applied to the data set #2 is probably what you think of first when…