Ivano Pagano wrote:If you'd like to share your impressions on OSGi-Servlet Bridge I'd be grateful since that's another interesting point of investigation for me.
First, I think that long-term there will be no need for the bridge. I think that because I think that long-term all application servers will expose the OSGi development model in much the same way that SpringSource dm Server already does and therefore, there's no need for a special bridge.
But until then...if you want to achieve some of the benefits of OSGi, but must deploy to a traditional web server, then the OSGi-Servlet Bridge is a must.
The bridge works like this: You create a web application that has a special
servlet (the bridge servlet) in its web.xml. When the web application is started up, it also starts up an OSGi runtime and installs a collection of bundles that make up that application. As the bridge servlet handles requests, it dispatches them to OSGi services that implement the javax.servlet.http.HttpServlet interface. So...the bulk of your web application still lives in the OSGi runtime, as services. The traditional part of the web app just has the bridge servlet to delegate to those servlet services.
To my knowledge, there are two implementations of the servlet bridge:
- The Equinox implementation:
http://www.eclipse.org/equinox/server/http_in_container.php
- The DynamicJava.org implementation:
http://dynamicjava.org/projects/dynamic-servlet-bridge
By far, my favorite among these two is the DynamicJava.org implementation. I like it mostly because I like the way they are thinking about having some OSGi bootstrap loader load the bundles for you. But, what I don't like about it is that they use their own DA-Launcher as that bootstrap loader and I would much prefer to use Pax Runner. So... (and this is where it gets a bit technical)
I've dug into the DynamicJava.org bridge and discovered that it is actually quite decoupled from DA-Launcher. It just uses a special servlet context listener to start DA-Launcher and then drop the OSGi bundle context in the servlet context for the bridge to use. Well...what if I were to implement a different context listener that did the same thing, but uses Pax Runner instead? Then I could use their bridge with Pax Runner...win-win!
But...alas...I haven't had time to implement that context listener. But if I did, then I could develop a rather thin WAR file that uses the bridge to delegate to servlet services in an OSGi runtime that is loaded up when the web app starts up. Here's the good part: The bundles that are loaded into the OSGi runtime
do not even have to be embedded in the WAR itself! They can reside almost anywhere that Pax Runner can find them (including, but not limited to, the filesystem, at HTTP URLs, in a
Maven repo, in an OBR repo, in a ZIP file, etc, etc). I can deploy the thin bridge part of my app in WebSphere (or whatever container I want) and keep my application elsewhere. (Think about it awhile and you'll realize how awesome this idea is.
)