Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To embed OSGi in servlet container or servlet container in OSGi?

I need to reuse code originally developed for an Eclipse RCP app (i.e. boxed as Eclipse plugin/OSGi bundle) in a servlet.

After reading a lot of blog posts, articles, wikis and so on I ended up at the point where I know that:

  1. An OSGi framework (Equinox in my case) can be embedded in a servlet container (Tomcat 7 in my case)
  2. or Tomcat can be embedded in an OSGi framework.

Equinox recommends the second option as being easier. But for production they recommend 1. I am unsure why. What is really better in which case and why?

I am a quite seasoned Tomcat user, will embedding Tomcat in Equinox change administering it heavily? or in other words, what will be different in Tomcat embedded in Equinox?

like image 555
Matt Avatar asked Apr 20 '12 20:04

Matt


3 Answers

First, does the code have any OSGi/Equinox dependencies besides the manifest? If not it should work just fine in a plain Tomcat.

My understanding is that embedding Tomcat in Equinox will change administering it heavily. Your folder layout including server.xml and catalina.sh will be gone. Instead you'll be managing an Equinox application probably through config admin.

Second there are two servlet programming and deployment models for OSGi. The first is HttpService in which you programmatically register your servlets and resources (you can also do this through an extension point). In this case your application is just a collection of bundles. However you can't use filters. The second is a web application bundle (WAB) which is an OSGified WAR.

like image 66
Philippe Marschall Avatar answered Nov 16 '22 19:11

Philippe Marschall


We have been doing a migration of rather complex web application that uses Jetty from non-OSGi to OSGi on Equinox. I have learnt about few things which definitely may drive your decision one way or another: - If you choose to use OSGi as a framework to run your app and e.g. option #2, everything your app consume will have to be OSGi bundles. Any external or third party of commercial libraries. If you use lots of open source, it is pretty easy to find bundles. Or if you can not find bundles you can always bundalize them yourself using BNDTools. Still this approach could be time consuming to figure out all proper dependencies and possible class loader issues requires hacks around OSGi - The approach of embedding OSGi into Tomcat, that may seem like safer and easier approach on the surface. Though I'm not sure you would get benefits from WABs in this case.

BTW one of the interesting benefits of WABs is that you can easily share code between WebApps, because they are deployed as bundles and you could simply export/import packages across them. Something which is not really possible with non-OSGi deployments today.

like image 35
user1456730 Avatar answered Nov 16 '22 21:11

user1456730


Apache Sling's maven-launchpad-plugin can produce a war file that embeds an OSGi framework (Apache Felix as standard, not sure if others are supported) and a set of bundles that you define. Can be used to run OSGi apps in Tomcat.

like image 26
Bertrand Delacretaz Avatar answered Nov 16 '22 21:11

Bertrand Delacretaz