Matt Raible has been building web applications for most of his adult life. He started tinkering with the web before Netscape 1.0 was even released. For the last 16 years, Matt has helped companies adopt open source technologies (Spring, Hibernate, Apache, Struts, Tapestry, Grails) and use them effectively. Matt has been a speaker at many conferences worldwide, including Devoxx, Jfokus, ÜberConf, No Fluff Just Stuff, and a host of others.

Matt is a DZone MVB and is not an employee of DZone and has posted 140 posts at DZone. You can read more from them at their website. View Full User Profile

My Experience With Java REST Frameworks (Specifically Jersey and CXF)

08.28.2009
| 16849 views |
  • submit to reddit
Recently I was tasked with developing a server-side REST strategy for a client. When I started working with them, they were using GWT RPC for exposing services. They wanted to move to RESTful services to allow for a more open platform, that multiple types of clients could talk to. There were interested in supporting SOAP and GWT RPC as well, but it wasn't required. They are using Spring, a custom namespace (for easily creating remote services) and an HTML documentation generator to expose their API in human readable form.

When I first starting developing, I chose to try Enunciate. From Enunciate's homepage:

Enunciate is an engine for creating, maintaining, and deploying your rich Web service API on the Java platform. If that sounds complicated, it's not. All you have to do is define your service interfaces in Java source code. ... Then invoke Enunciate.

Sounds pretty sweet, eh? At first glance, the things I liked about Enunciate were:

  1. The ability to generate multiple endpoints (and clients).
  2. Generates nice-looking documentation.
  3. Allows selecting different frameworks (for example, CXF instead of JAX-WS RI).

Initially, the hardest part of using Enunciate was integrating it into my project. This was somewhat related to having a multi-module project, but moreso related to getting the settings right in my enunciate.xml file. After getting everything working, I encountered a few Spring wiring issues with the GWT Endpoints and with Jersey's Spring support.

The good news is I believe most of these issues were related to my project and how it proxies Spring beans that Jersey couldn't find. Jersey's Spring support only supports annotations at this time, so I was unable to tell it the proxied bean names via XML (or even its own annotations). I'm sure this problem is solvable, but after struggling with it for a day or two, I decided to give up on Enunciate. I had to get something working, and fast.

At this point, I was back to the drawing board. I knew there were plenty of good Java REST frameworks available, but Spring and CXF (for SOAP) were already available dependencies in my project, so I chose that route. I was able to get something up and running fairly quickly with this tutorial and CXF's JAX-RS documentation. I ran into an Invalid JSON Namespace issue, but was able to solve it by adding a custom namespace.

It's not all rosy though, there are still a couple CXF issues I haven't solved:

While CXF does take a bit of XML for each service, it's kinda slick in that it only requires you to annotate your service interfaces. It also generates documentation for your services (WSDL and WADL), but it's not as pretty as Enunciate's. To solve this, I added Enunciate for documentation only. To make Enunciate work, I did have to add some annotations to my service implementation classes and parse the generated HTML to fix some links to CXF's services, but ultimately it works pretty well.

In the end, I recommended my client not use Enunciate for generating endpoints. This was primarily related to their unique Spring configuration, but also because I was able to easily use the same classes for REST, SOAP and GWT Endpoints. However, I will continue to keep my eye on Enunciate. It could be very useful for the upcoming appfuse-ws archetype. I'm also eager to see better GWT support and the ability to generate Overlay types in future releases

From http://raibledesigns.com/rd/entry/my_experience_with_java_rest

Published at DZone with permission of Matt Raible, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mittal Bhiogade replied on Fri, 2009/08/28 - 8:35am

Hi Matt,

Did you consider Jersey ? Or was there any reason to not even consider because of project/time constraints ?

- Mittal

 

Matt Raible replied on Fri, 2009/08/28 - 10:00am in response to: Mittal Bhiogade

Mittal - I tried Jersey both as part of Enunciate and I tried it standalone. As I eluded to in the article, it didn't work for my project because of some Spring integration issues (I believe it's bec ause we're proxing our Spring beans). For the specific error, please see this message.

David M. replied on Fri, 2009/08/28 - 10:17am

We've implemented a REST-like interface using RESTEasy with the integrated JAXB support.  I've found it fairly easy to setup and use from both the server and client side.  The hardest part was getting the XML annotations to match what I wanted since we had a complex XML input to the PUT method.  Using the Poster add-on to Firefox made for some rapid development.  I really like that the simple example worked right out of the box with little fuss which can't be said for some frameworks.  It is fairly new but with the JBoss backing, it appears mature enough.

- Dave

Nilabh Sagar replied on Mon, 2012/10/08 - 10:05am

Hi Matt,

Few days back I managed to call Spring REST services from GWT. have a look into my post "http://css.dzone.com/tips/spring-rest-services-gwt". it might be helpul for you.

Nilabh

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.