| DynamicServlet-Bridge Overview |
|
|
DynamicServlet-Bridge allows Web Applications to delegate HTTP requests to OSGi services that implement the Servlet interface. This way, one could make application's Servlets dynamic in non-osgi Servlet Containers so Servlets could be updated, added and removed at runtime no matter whether the Servlet Container supports OSGi or no. It's worth mentioning that bridging Servlets is a way of implementing HTTP Services in OSGi, not the way of implementing HTTP services in OSGi. But as for bridging servlets, DynamicServlet-Bridge is the simplest way to bridge OSGi servlets with non-osgi Web Applications and it has the most flexible design of solutions that aim to solve this task. Why use a Servlet Bridge?Suppose that you want the servlets of your application to be dynamic but you don't want to use the OSGi HTTP Service for one of the countless reasons like: No real support for this service, the service itself is not as stable as well known Servlet Containers like Apache Tomcat, you don't want to be at the risk of finding many missing features along the way or many of the other risks associated with an immature technology. At times like this, you might want to use the new dynamic technology (the OSGi-based application) alongside the mature and stable technology (be it a Servlet Container or an Application Server) not the dynamic technology completely replacing the mature technology. Servlet Bridges provide you with such option by allowing the non-osgi Web Application delegate HTTP requests to OSGi Servlet Services provided by an OSGi-based application. ExampleThe example Web Application contains two Bridge Servlets that delegate requests to two OSGi Services that implement the Servlet interface. The Services are deployed in two separate bundles, so they can be updated separately. You can update these bundles to verify the fact that Servlets are updated or you can remove the bundles to see how the application behaves when there are no matching OSGi Servlet services. The WAR file for this application can be downloaded from here. Tomcat instance with the example Web Application can be downloaded from here. Please, make sure to read the readme.txt file before running the application.How DynamicServlet-Bridge works?First an OSGi Environment from which Servlet services would be consumed should exist and the Servlet Bridges must have a reference to it – This is done by passing the bundle context in the Servlet Context object. A Servlet Bridge also needs to know which OSGi Servlet Services it should delegate the requests to, this is done by specifying the “service-filter” attribute of the servlet – This attribute represents an LDAP filter against which all the OSGi Services that implement the Servlet interface will be matched. If more than one Service matches the filter specified by the servlet then matching against the 'urlPattern' property of the OSGi Service will be done and a Service with the longest matching URL Pattern will be chosen. If none of the OSGi Services defined the 'urlPattern' property then the first available service will be chosen. |