07.12.2010

Eclipse Virgo + Snaps: Modular Web Apps, finally, Part 1

While looking for state-of-the-art technologies to build modular web apps, I stumbled over the Eclipse Virgo project. It is the Spring DM Server, donated to the Eclipse ecosystem. Using a prototype extension, Snaps (formerly called Slices), you can now compose a web app from code and resources distributed over many OSGi bundles. Modularization, finally!

Imagine a web application that provides you with a special feature called "Upload plugin". You would be able to write a plugin in eclipse, using APIs from that application delivered to you through other plugins. Then you could upload your new plugin and would immediately notice the extensions to the web application.

More important than the hot deployment is the standardized modularization API available. A plugin marketplace could evolve (yes, remember Eclipse plugins!) from which you could add functionality to your application even without coding! Now imagine this environment deployed into a cloud infrastructure: The ideal PaaS for java web development!

Installation and Test

  1. Download Virgo Web Server.
  2. Unzip it somewhere.
  3. Start bin/startup.sh.
  4. Goto http://localhost:8080.
  5. Play around with the admin console.
  6. Checkout git://git.eclipse.org/gitroot/virgo/org.eclipse.virgo.snaps.git
  7. Import all projects therein into Eclipse (use a fresh workspace).
  8. in snaps, say git submodule update --init (this creates content in ./virgo-build)
  9. Stop the virgo server (or tests will fail in the next step)
  10. in ./build-snaps, say ant clean clean-integration test package
  11. say cp target/package-expanded/snaps-1.0.0.BUILD-20101206191709/repository/usr/* somewhere/virgo-web-server-2.1.0.RELEASE/repository/usr/
  12. Start the server again, you should not notice big differences
  13. Now cd to ./org.eclipse.virgo.snaps.test/src/test/resources
  14. cp simple-host.war somewhere/virgo-web-server-2.1.0.RELEASE/pickup/
  15. Look into the server console and observe how the bundle is deployed
  16. Goto http://localhost:8080/simple-host only to get a "index" answer.
  17. Goto http://localhost:8080/simple-host/simple/index.jsp only to get a 404.
  18. cp simple-snap.jar somewhere/virgo-web-server-2.1.0.RELEASE/pickup/
  19. Goto http://localhost:8080/simple-host/simple/index.jsp and get an "OK" answer.
  20. You may now start and stop the simple-snap bundle in the admin console and watch the web resource appearing and disappearing.
Congratulations! - You just installed your very first really modularized web app!

What happened?

Let's first examing simple-host, the host webapp of our test. It is a pretty normal WAR file. Since OSGi R4 specifies a way to deploy WARs as bundles, Virgo is able to do that. Moreover, in the web.xml, you can find a filter called "host-filter" of class org.eclipse.virgo.snaps.core.SnapHostFilter.
The is the core component of snaps, re-routing requests for different contexts to different OSGi-bundles, called snaps.
simple-snap is an example of such a snap. Its web.xml could very well be empty (but isn't here - it contains several test resources).  Its MANIFEST.MF, besides usual entries, contains the following:
Snap-Host: simple.host;version="[1.0, 2.0)"
Snap-ContextPath: /simple
This way, a snap is tied to a specific host and has to declare under which (sub-) context it is serving resources.

In Part 2, I want to develop my first own snaps from scratch. Read on!