Conquering the challenge of integrating JAX-RS (REST) with OSGi modularity

OSGi and REST based web services are two incredibly popular technologies that have evolved separately over the past few years. But now developers are tackling the challenge of bringing these two technologies together. Here's how they are making that integration happen.

In the open source Java community, the Eclipse Foundation has a long history of supporting developers with new and better ways to create and deliver applications. In the past three or four years, the Java community has taken great strides in two key areas that have made server side development significantly easier: RESTful web services and modularization through OSGi. But now the big challenge is what happens when we want to bring these two technologies together? This is the latest challenge the enterprise community is trying to address.

People always struggle to connect OSGi concepts with JAX-RS concepts. We provide the glue.

Holger Staudacher, EclipseSource

What does a RESTful web service implementation like Apache CXF or Apache Wink have to do with OSGi? Well, until recently, it's been difficult to work with JAX-RS in a way that's deeply integrated with OSGi. This disconnect has left developers struggling to address issues such as HttpService integration instead of spending their time focusing on effective RESTful API development.

JAX-RS and OSGi integration

 "We are mixing JAX-RS with OSGi on the service level. Because OSGI has a concept called service. You define a class and register it as a service and the framework instantiates it," said Holger Staudacher, a software developer and consultant at EclipseSource "If you register a service which is annotated with JAX-RS annotations, we pick it up and publish it also as a REST service. The benefit the user has then is that they can consume it in the OSGi instance directly, or via HTTP."

The OSGi JAX-RS connector that Staudacher is heavily involved in developing and maintaining via Eclipse is making things even simpler. "People always struggle to connect OSGi concepts with JAX-RS concepts. We provide the glue. What we encapsulate is the JAX-RS implementation. If you use the connector, you do not need to care about the implementation of JAX-RS. You can use Jersey, Restlet, whatever, you only need to know OSGi services and the JAX-RS API (mainly the annotations)." With connectors doing the heavy lifting of integration, developers may be able to concentrate more on building truly RESTful services. That's an important benefit.

Struggling with OSGi and REST

It's an unfortunate fact that many development teams still haven't achieved an advanced understanding of the REST concept itself. As Holger pointed out, implementing remote procedure calls is not the same thing as implementing REST. One common pitfall he's noticed is that developers unfamiliar with the complete scope of REST often forgo hypermedia content.

Simon St. Laurent, the co-chair of Fluent 2014 and Senior Editor at O'Reilly, described the benefits of hypermedia for RESTful APIs, "Hypermedia changes the chunking. Instead of changing little pieces individually with lots of transactions all over the place, you're sending out a more complete document with links in it that act as options to the next place you want to go to." Hypermedia is becoming an essential part of the REST picture in an age where the documents being passed from computer to computer are larger than ever. In fact, it's the third step in the Richardson Maturity Model that developers must achieve if they wish to enter into the Glory of REST.

Taking REST and OSGi to the next level won't be simple. However, contributors at the Eclipse Foundation are hard at work coming up with open source APIs and other tools that are sure to help.

What is your experience integrating OSGi and REST? Let us know.

Dig Deeper on Application Integration middleware

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.