Today: November 3, 2024 6:31 am
A collection of Software and Cloud patterns with a focus on the Enterprise

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:

Comments

  1. 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.

    • 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.

  2. Avatar for Daniel Watrous Kristin Maughan : June 17, 2014 at 9:27 am

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

  3. 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?

    • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.