OSGi JAX-RS Connector 2.0 released

Back in January 2012, I wrote about the release of the OSGi JAX-RS connector in version 1.0. The connector gives you the opportunity to publish resources by registering @Path annotated types as OSGi services. I’m glad to say that the connector is in production use in many projects. It is pretty stable and as a result there was not much need for maintenance. So, why release a version 2.0? A few weeks ago I wanted to provide a small REST API using Apache Karaf as runtime. For this I also wanted to use the JAX-RS connector. Unfortunately, I had to accept that the connector was not able to run on Karaf and Felix because of certain issues.

I had to rework some of the connector internals and update the Jersey bundles to 1.13.0 to make it work. But, internal rework is no reason for a 2.0, right? Unless, during the rework something results in a breaking change. In version 1.0 of the connector all resources were registered on /. Sadly, this is not possible using Karaf and it’s HTTPService implementation. Therefore, the new root path of the registered resources is /services. The good news is that it’s configurable ;). You can use the config admin to change the root path. For this the service.pid is com.eclipsesource.jaxrs.connector. The only property supported is root which needs to be a valid path (like with servlets, it has to begin with /).

To put it all together, the internal rework, the Jersey update and the new path gave me reason to bump it to 2.0 to make the breaking change visible. I hope you like the new version. As a reminder here are the most important resources:

GitHub repository: https://github.com/hstaudacher/osgi-jax-rs-connector

p2 repository: http://hstaudacher.github.com/osgi-jax-rs-connector

As always, feel free to comment ;).

followme OSGi JAX RS Connector 2.0 released

8 Responses to “OSGi JAX-RS Connector 2.0 released”

  1. Lars Vogel says:

    I’m not sure if see how to use this. Lets say I have a server which offers RESTful API, my assumption is what I could use your connector to publish these resources as OSGi services. And afterwards I could for example use OSGi remote services in an RCP application to connect to the server.

    Is that the right use case?

  2. Hi Lars,
    no it’s not. In your tutorial [0] you have described how to register the @Path annotated resources. You have registered the service dispatcher within a web.xml.

    In an OSGi environment such web.xml simply does not exist. As a result you have to register the REST service programatically. This can be done using Jersey’s API with some minor classpath issues. The bad thing about this is you have to register every REST service by yourself.

    Here the connector comes into the game. Instead of registering the REST services by yourself you can use the connector. It does the wiring from your @Path classes to Jersey for you. The connector can do this because you have to register you @Path pojo as an OSGi service. The connector has a service tracker and will be notified about every @Path pojo registration. When a @Path pojo will be registered the connector wires it up with jersey and the REST service is published.

    The consumption of the services has nothing to do with Remote Services. You can consume your REST service the way you prefer. The connector is about publishing REST services only. My goal was to provide a way to publish rest services in an OSGi container as easy as possible.

    So, when you want to use OSGi as a server runtime (without tomcat etc.) and you want to publish REST services the connector can make you life much easier :)

    I hope this clarifies the use case. Feel free to dig deeper ;)

    [0] http://www.vogella.com/articles/REST/article.html

  3. Hendy Irawan says:

    Hi,

    For those interested, it’s also nice to use CXF in Karaf with JAX-RS support built-in. To register REST resources you use Blueprint.

    An example Blueprint XML for CXF & JAX-RS from our project : http://pastebin.com/CUjQmWrx

  4. Hugo says:

    Hi,
    I’m having a problem installing your connector to my OSGi instance, it gives the following error:

    The bundle “com.eclipsesource.jaxrs.connector_2.0.0.201208151950 [125]” could not be resolved. Reason: Missing Constraint: Import-Package: org.osgi.service.cm; version=”[1.4.0,2.0.0)”

    Do you know by any chance what’s the problem? Do you think your version 1.0 of the connector might solve the problem? Do you still have the link to version 1.0.0?

    Thank you

  5. Hi,
    the package org.osgi.service.cm contains the OSGi configuration admin [1]. The configAdmin is used to configure services. Which OSGi implementation do you use? I’m sure your implementation also supports the configAdmin. Just add it to your container…

    [1] http://www.osgi.org/javadoc/r4v401/org/osgi/service/cm/package-summary.html

  6. Chris Brind says:

    Hi Holger,

    Quick question, hopefully… I’m trying to get this running but the bundle seems to get stuck in the “starting” state. I wonder if I’m missing any dependencies or something? You can see my configuration here:

    https://dl.dropbox.com/u/2451973/Screen%20Shot%202012-10-23%20at%2023.48.53.png

    Thanks in advance.

    Cheers,
    Chris

  7. Hi Chris,
    can’t see any miss configuration. The dependencies of the connector are jersey, the HTTPService and the ConfigurationAdmin. It seems that all are installed within your instance. Have you taken a look at the log of the framework? Maybe this brings up new information. Please keep me posted about the progress.

  8. Chris Brind says:

    Nothing in the logs, thought manually stopping and starting it seems to get it in to the Active state. Haven’t had chance to test my resource yet though. :)

8 responses so far

Written by . Published in Categories: Planet Eclipse, Planet OSGi