Monthly Archive for: ‘January, 2011’

Dynamic modular Web Applications with Vaadin and OSGi

40

I am a big fan of both OSGi and GWT (Google Web Toolkit). Unfortunately these two technologies don’t fit together very well. When you want to run OSGi on the server, RAP (Rich Ajax Platform) is one proven approach to go. While I like RAP a lot, you have to have quite a lot of Eclipse RCP know how for using it. Another alternative, if your want to run OSGi on the server and provide a modular, dynamic UI is Vaadin. Btw, Vaadin is the Finnish word for female reindeer. Vaadin is a server side RIA framework that uses GWT as rendering engine. In the last couple of days a played a bit around with Vaadin and I have to admit, I like it a lot. So, I wrote a little dynamic OSGi Vaadin demo (Download link and instructions are below). My goals for the demo were:

  • Provide Bundles that contribute directly to the web application’s UI
  • Just starting and stopping bundles should contribute/remove UI elements and functionality
  • I wanted to implement something similar to my dynamic Swing OSGi demo

Before I started with Vaadin, I found a few interesting reads and code sample regarding OSGi and Vaadin:

But back to the demo, here is a screen shot running the application in Firefox:

The idea is to support two kinds of UI contributions: views and actions. The views are inserted in a tab folder, the actions appear in the toolbar and the Action menu. I implemented a little OSGi agent as a view (Bundle View). This view shows a selection of bundles currently available. By checking/unchecking a bundle, it will be activated/stopped on the server side. If you press “Deselect All”, all bundles go to resolved state and all the UI contributions disappear immediately:

Of course you could start and stop bundles from the OSGi console directly, then you would have to refresh the browser to get the changes displayed. To get the demo running on your local machine, follow these steps:

  • Make sure you have an Eclipse IDE installed
  • Download the demo sources and target platform osgi-vaadin-demo.zip (6.8 MB)
  • Import all projects from the zip file into Eclipse
  • Open the project “com.siemens.ct.osgi.vaadin.target”
  • Double-click vaadin.target (That opens the target platform definition in an editor)
  • Click on “Set as Target Platform” in the right top corner of the editor
  • Now everything should compile
  • Start the Run Configuration “OSGi Vaadin Demo”
  • Open the following URL in your favorite browser “http://localhost/com.siemens.ct.osgi.vaadin.pm.main
  • If everything went well, you see the demo in your browser
  • if you don’t want to run Jetty on the default port 80, add a VM argument in the launch configuration, e.g.: -Dorg.osgi.service.http.port=8080
  • Play around with it, activate/stop bundles and watch the console log

In the next weeks I plan to go a little bit more into details of the demo, how OSGi declarative services are used, how to contribute to Vaadin Themes, etc.

Stay tuned and have fun!

Kai

Follow me on Twitter