Question

We have an application where where we would like to run Jersey using OSGi Equinox. Please provide any help or pointers. All that I have been getting on net is using Apache Felix. I do not want to do that. My App uses the below things

Angular JS for Client side code Jersey for Rest Services OSGi Equinox and Jetty for deployment.

Please suggest if this is possible and if yes then how

Was it helpful?

Solution

See https://github.com/everit-org/osgi-remote-jersey/tree/v1.0.2

  • Go to tests directory
  • Edit pom.xml and change the jetty.port in felixtest environment to a port you like
  • run "mvn install" on tests
  • go to target/eosgi-dist/felixtest/bin
  • run runConsole.bat (or runConsole.sh on linux)
  • open localhost:port/system/console and see what is installed (basically all of the maven dependencies of the tests project)

The solution works on felix and equinox as well.

Update based on the question (without an extender):

You can implement the same logic as the extender does. In short:

ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(myJAXRSAnnotatedObjectOrClassType);
Servlet servletContainer = new ServletContainer(resourceConfig);
// register the newly created servlet instance to the server

You can register that servlet in several ways:

  • via HTTPService
  • with whiteboard pattern
  • By creating a wab and
    • Creating an own Servlet that wraps the jersey servletContainer instance
    • Configure a new servlet in the web.xml that has the type ServletContainer

You can call resourceConfig.register multiple times. In this way, you can register many JARS annotated classes under one servlet instance.

With resourceConfig.register you can not only register JAXRS annotated classes, but also any component that Jersey knows about. For example, if you want to add JSON parsing feature, you can use:

resourceConfig.register(JacksonFeature.class);

OTHER TIPS

Have you looked at the OSGi JAX-RS Connector? It's using Jersey and was initially developed and tested on Equinox. AFAIK they also do support Felix.

Another option would be Eclipse Gyrex. But it's more a complete stack based on Equinox, Jetty and Jersey and might not be the best choice if you prefer assembling your own stack. However, it's still at Jersey 1.x. An upgrade is scheduled after the upcoming Luna release.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top