Java – Selecting a JAX-RS Implementation for a New Project

javajava-eerest

I'm starting a new Java project which will require a RESTful API. It will be a SaaS business application serving mobile clients.

I have developed one project with Java EE 6, but I'm not very familiar with the ecosystem, since most of my experience is on the Microsoft platform.

Which would be a sensible choice for a JAX-RS implementation for a new project such as described?

Judging by Wikipedia's list, main contenders seem to be Jersey, Apache CXF, RESTeasy and Restlet. But the Comparison of JAX-RS Implementations cited on Wikipedia is from 2008.

My first impressings from their respective homepages is that:

  • CXF aims to be a very comprehensive solution (reminds me of WCF in the Microsoft space), which makes me think it can be more complex to understand, setup and debug than what I need;
  • Jersey is the reference implementation and might be a good choice, but it's legacy from Sun and I'm not sure how Oracle is treating it (announcements page doesn't work and last commit notice is from 4 months ago);
  • RESTeasy is from JBoss and probably a solid option, though I'm not sure about learning curve;
  • Restlet seems to be popular but has a lot of history, I'm not sure how up-to-date it is in the Java EE 6 world or if it carries a heavy J2EE mindset (like lots of XML configuration).

What would be the merits of each of these alternatives? What about learning curve? Feature support? Tooling (e.g. NetBeans or Eclipse wizards)? What about ease of debugging and also deployment? Is any of these project more up-to-date than the others? How stable are them?

Best Answer

I've grown to love Dropwizard for an overall solution

Rather than go with some huge application container approach, Dropwizard advocates a lightweight solution that offers much faster development cycles. Essentially, it provides the glue for the following well-known frameworks:

  • Jetty (HTTP)
  • Jersey (JAX-RS)
  • Jackson (JSON or XML)
  • Guava (excellent additions to JDK libraries)
  • Metrics (real time application monitoring)
  • Hibernate Validator (input verification)
  • OAuth (RESTful authentication)

The combination of the above, coupled with a solid approach to functional testing, gives a complete solution to getting your service up and running quickly.

Yeah? And the JAX-RS question I asked...

You'll notice that their choice was Jersey, the reference JAX-RS implementation. Being a RESTEasy guy I thought this would be a problem, but there was zero learning curve. The two are largely interchangeable. However, I would say that the Jersey client offered a fluent interface for constructing tests. An example would be...

 @Override
  protected void setUpResources() {
    addResource(new HelloWorldResource("Hello, %s!","Stranger"));

    setUpAuthenticator();
  }

  @Test
  public void simpleResourceTest() throws Exception {

    Saying expectedSaying = new Saying(1,"Hello, Stranger!");

    Saying actualSaying = client()
      .resource("/hello-world")
      .get(Saying.class);

    assertEquals("GET hello-world returns a default",expectedSaying.getContent(),actualSaying.getContent());

}