Alex Rivera | Logout

How to modularize a JSF/Facelets/Spring application with OSGi?

Asked 2010-04-04T19:48:38.360
26

I'm working with very large JSF/Facelets applications which use Spring for DI/bean management. My applications have modular structure and I'm currently looking for approaches to standardize the modularization.

My goal is to compose a web application from a number of modules (possibly depending on each other). Each module may contain the following:

  • Classes;
  • Static resources (images, CSS, scripts);
  • Facelet templates;
  • Managed beans - Spring application contexts, with request, session and application-scoped beans (alternative is JSF managed beans);
  • Servlet API stuff - servlets, filters, listeners (this is optional).

What I'd like to avoid (almost at all costs) is the need to copy or extract module resources (like Facelets templates) to the WAR or to extend the web.xml for module's servlets, filters, etc. It must be enough to add the module (JAR, bundle, artifact, ...) to the web application (WEB-INF/lib, bundles, plugins, ...) to extend the web application with this module.

Currently I solve this task with a custom modularization solution which is heavily based on using classpath resources:

  • Special resources servlet serves static resources from classpath resources (JARs).
  • Special Facelets resource resolver allows loading Facelet templates from classpath resources.
  • Spring loads application contexts via the pattern classpath*:com/acme/foo/module/applicationContext.xml - this loads application contexts defined in module JARs.
  • Finally, a pair of delegating servlets and filters delegate request processing to the servlets and filters configured in Spring application contexts from modules.

Last days I read a lot about OSGi and I was considering, how (and if) I could use OSGi as a standardized modularization approach. I was thinking about how individual tasks could be solved

Edit
Report

2 Answers

2

The "web module deployment descriptor fragment" (aka web-fragment.xml) introduced by the Servlet 3.0 specification would be nice here. The specification defines it as:

A web fragment is a logical partitioning of the web app in such a way that the frameworks being used within the web app can define all the artifacts without asking devlopers to edit or add information in the web.xml.

Java EE 6 is maybe not an option for you right now though. Still, it would to be the standardized solution.

answered 2010-04-09T21:53:22.680
0

You should look into Spring DM Server (it's being transitioned to Eclipse Virgo but that's not been released yet). There's a lot of good things in the recent OSGi enterprise spec which has also just been released.

Some of the Spring DM tutorials will help, I'd imagine. But yes, it's possible to have both resources and classes loaded from outside the web bundle using standard modularity. In that, it's a good fit.

As for the session context - it gets handled as you would expect in a session. However, you might run into problems with sharing that session between web bundles to the extent that in not sure if it's even possible.

You could also look to have a single web bundle and then use e.g. the Eclipse extension registry to extend the capabilities of you web app.

answered 2010-04-04T20:04:19.057

Your Answer