OSGi-JAX-RS Connector 2.1.0 released

Two months ago the OSGi JAX-RS was released in Version 2.0. Today I’m proud to announce Version 2.1. In addition to minor improvements, a new feature was added based on the work of Dirk Lecluse. It’s now possible to register @Provider annotated objects as OSGi services. The @Provider annotation is used to register custom de/serialization. Now you can implement a custom MessageBodyWriter, MessageBodyReader, ContextResolver or ExceptionMapper, annotate it with @Provider and simply register it as OSGi service. All the connector does is wire together the resources with the provider.

connector 300x189 OSGi JAX RS Connector 2.1.0 releasedAs a side note: A few days ago I was asked why I would like to register @Path or @Provider annotated objects as OSGi services. The answer is that it enables you to wire up your REST interface with the rest of your system loosely. For example, the serialization in my system is an OSGi service too. So, when registering an @Provider as a service I can use Declarative Services to hook my serialization object into the provider. This enables me to separate domain and framework code because I don’t have to get the service myself – which is a good thing, right? icon wink OSGi JAX RS Connector 2.1.0 released

If you would like to use the connector here are the resources to start with:

4 Responses to “OSGi-JAX-RS Connector 2.1.0 released”

  1. Eric says:

    Hi

    Do you think your connector could work with Glassfish? I tried installing it (not an easy task since Glassfish is using a different version of Jersey) and I was able to get it in Active state but when I try to install one of the samples it fails with things like

    java.net.URISyntaxException: Illegal character in path at index 30: bundle://281.0:0/launch/JAX-RS Example DS.launch

    or

    java.lang
    .IllegalStateException: org.osgi.service.http.NamespaceException: alias already registered
    Caused by: org.osgi.service.http.NamespaceException: alias already registered

    Regards

  2. Hi Eric,
    the first thing is really strange because this is just the launch configuration file for within Eclipse. Please try to remove it from the builded examples.

    By default the connector will register your services with the context name “services”. So registering a @Path( “/test” ) resource will lead to /services/test. In Glassfish is there anything registerd with services? If yes you can use the OSGi configuration admin to change the /service path to something of your choice. See the readme for an how to.

    Hope this helps.

    Cheers Holger

  3. Thomas says:

    Hi Holger,

    i’m using your connector for my osgi services. now i want to convert my pojos to json transparently. some tutorials around the internet suggest me to configure my servlet with an init param (like here: mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson) . currently i’m using an equinox bridgeservlet which delegates the servlet requests to a http service, and finally to your dynamically registred “rest servlet”. how i can configure this servlet init params? cause, currently i’m stucked with Exceptions like this: “A message body writer for Java class java.util.ArrayList, and Java type java.util.List, and MIME media type application/json was not found”

    thank you in advance
    thomas

  4. You don’t need any init params. Just write your own @Provider for the de/serialization and register them as OSGi services to. The wiring will be done under the hood by Jersey.

4 responses so far

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