[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[equinox-dev] Web applications based on OSGi HttpService

Hi all,

last year I filed bug162132:
[server] webapp extension point for org.eclipse.equinox.http.registry.

I've made progress in the last few weeks, and recently have made an initial implementation publicly available.

The basic idea is to provide easy support for web applications using servlets, JSP's, filters, mime-types, welcome-files, declarative security, etc. based on OSGi HttpService (and its implementations, e.g. Jetty based, ServletBridge, Knopflerfish, Felix). The web deployment descriptor (/WEB-INF/web.xml) will be parsed, all configured stuff will be transparently wrapped onto the HttpService, resources will be registered automatically, etc.

The current implementation is structured as 3 components (bundles):

1. org.eclipse.equinox.webapp.service

    public interface WebAppService {
        public Object registerWebApp(String webContext, Bundle bundle,
                String bundleResourcePath, String webXml, Dictionary options)
                throws WebContextException;

        public void unregisterWebApp(Object handle);

This service will be registered in the OSGi service registry, where you can programmatically register and unregister a web application, e.g.

    // when service tracker get WebAppService added
    Object handle = webAppService.registerWebApp("/demo", bundleContext.getBundle(),
        "/WebContent", null /* defaults to /WebContent/WEB-INF/web.xml" */, null);

    // when service tracker get WebAppService removed

and handle the web application lifecycle as required by your application.

2. org.eclipse.equinox.webapp.registry

Alternately a web application can be contributed via an Eclipse extension point:

         name="Demo Application"
          <!-- webXml defaults to /WebContent/WEB-INF/web.xml -->


The bundle lifecycle follows the extension point lifecycle, so install / uninstall will contribute / remove the web application to/from OSGi HttpService.

. org.eclipse.equinox.webapp.extender

The extender implementation will observe all bundles started or stopped within the OSGi platform. If the extender file (here /WEB-INF/web.xml) is available, the bundle is treated as a web application, and seamlessly registered with the HttpService.

This is quite cool, as it allows for easy deployment of existing web applications (WAR file), with the only need to OSGi'fy the WAR file as an OSGi bundle (use bnd tool from Peter Kriens).

For example, the demo application is structured this way

demo.jar (bundle, OSGi'fyed version of demo.war)
    /META-INF/manifest.mf (an OSGi bundle, e.g. with)
        Bundle-ClassPath: .,/WEB-INF/classes,/WEB-INF/lib/mylib.jar

The current state of implementation:

Supported features are:
The implementation requires bugfixing, more refactoring, more test cases (lifecycle, correct registering orders, ...). Declarative security is completely missing.
I am just starting to write some docs, adding a tutorial, sample application, but this needs a little bit more time...

The contributed code to the bug 162132 is of 2007-09-14 is now slightly out-of-date. If you want to give it a try, I'd encourage you to use the CVS version, as the code is still evolving. Currently the implementation is hosted in CVS at project sse-examples at SourceForge.net, at

    :pserver:anonymous@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:/cvsroot/sse-examples, webapp-incubator

You can also use a project set file with implementation, test bundles, test cases, few docs:

Feedback is appreciated and welcome.

Regards, Jochen