Daniel Watrous on Software Engineering

A Collection of Software Problems and Solutions

Software Engineering

Software licensing: Jersey framework for REST

I did some investigation into building the RESTful API for the software licensing system using wicket. At first I was encouraged that URL management was so easy (nevermind that really old article I just linked to).

Wicket Not Ideal for RESTful APIs

In the end I decided that wicket was not a good choice for the RESTful API. The crux came in treating HTTP methods differently. In other words, for a given resource URI, I want to do something different for GET, POST, PUT and DELETE. That’s not one of wicket’s strengths, so I moved on.

The first framework I looked at had a really slick look. I know that’s not necessarily an indication of technical superiority, but the simplicity of the homepage made me believe that Restlet would be a good choice. But before making my choice, I looked for references and found this stackoverflow discussion.

Jersey Wins

I had seen Jersey before reading that, but was turned off thinking I had to dive deep into glassfish and other technologies. The stackoverflow discussion convinced me to give Jersey a try and I’m so glad that I did. In about a half an hour I had my initial API calls framed and responding to web calls in Google App Engine.

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
package com.danielwatrous.softwarelicensing;
 
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
 
//The Java class will be hosted at the URI path "/sitelicenses"
@Path("/sitelicenses")
public class SiteLicenses {
 
	@GET
	@Produces("text/plain")
	public String getAllSiteLicenses() {
		// Return some cliched textual content
		return "Hello World GET";
	}
 
	@POST
	@Produces("text/plain")
	public String createNewSiteLicense() {
		return "Hello World POST";
	}
 
	// @PUT
	// @DELETE
}

I followed this extremely concise Jersey + GAE tutorial to get things going. There were more jar files required that are shown there. Otherwise I can’t believe how easy it was to get my RESTful API framed in and working.

TIP:

About a year ago I found a great tool to explore REST and test RESTful services. It’s a Chrome plugin named Simple REST Client. This makes it possible to send requests to a URI using any of the HTTP methods and see the full response, including headers. Here’s a screenshot of my first API response:

5 Comments Software licensing: Jersey framework for REST

  1. Waqas Sadiq

    Why are you using restlet or jersey and wicket. Spring framework 3 is there to help you with its built-in support for Restful Apis. This framework take care of everything for you.

    Reply
    1. Daniel Watrous

      Hi Waqas,

      I considered Spring and I think you’re right that it would provide all the functionality needed for this project. However, Jersey was easy and I had it up and running in about 30 minutes. The annotations made the code very concise and very readable. Since I lacked experience with Spring I skipped the learning curve on this project.

      Reply
  2. Kristin Maughan

    I found this overview to be very helpful in understanding Jersey’s strength’s compared to other frameworks. Thanks for posting.

    Reply
  3. Ruchit Shinde

    hi Daniel Watrous,
    I wanted to use jersey framework in an application where i will be adding my business logic without modifying any jersey framework source. Can i still sell this software?

    Reply
    1. Daniel Watrous

      I don’t think any of the open source licenses prevent you from selling your software, including the GPL. However, some require that you also distribute any source code so others may do what they want with it. The way most commercial contracts around open source software work is that they give away the source and sell support contracts.

      Reply

Leave A Comment