Lightweight OSGi Applications using RAP’s Widget Toolkit

Lightweight OSGi Applications using RAP’s Widget Toolkit

Update 2: The new interfaces have been renamed again in RAP 1.5M7. Please refer to this post for the details and check out the updated code example.

Update: APIs have changed a bit meanwhile, so I updated the code below accordingly. Entry points are now registered by path, and JEE_COMPLATIBILTIY has become the default mode, which makes the main loop obsolete in this kind of applications.

RAP is well known as an “RCP for the web browser”, including workbench, extension points, and all that stuff. Indeed, one of the greatest features of RAP is its ability to reuse RCP code in web applications. But did you know that you can also use RAP’s widget toolkit (RWT) to create simple web UIs for your applications, without the heavy weight Eclipse UI stack?

With RAP 1.5, you can now simply include RWT in any OSGi application. You only need two bundles: org.eclipse.rap.rwt (the RAP widget toolkit itself) and org.eclipse.rap.rwt.osgi which integrates RWT with the OSGi HTTP service. There are no tie-ins with Equinox anymore, thus RAP also works with other OSGi containers.

To create a UI with RWT, you have to implement the interface IEntryPoint, here’s a simple example:

  public int createUI() {
    // Create a maximized top-level shell without trimmings that represents the main "page"
    Display display = new Display();
    Shell page = new Shell( display, SWT.NO_TRIM );
    page.setMaximized( true );
    page.setLayout( new GridLayout() );

    // Create contents of main shell
    Label label = new Label( page, SWT.NONE );
    label.setText( "Hello" );
    Button button = new Button( page, SWT.PUSH );
    button.setText( "World" );

    // Open the top-level shell and run the main loop to process events
    return 0;

Now what’s new is that, instead of registering this entry point with an extension point, you can now implement the new ApplicationConfigurator interface like this:

  public void configure( Context context ) {
    context.addEntryPoint( "/simple", SimpleEntryPoint.class );
    context.addBranding( new AbstractBranding() {
      public String getServletName() {
        return "simple";
      public String getTitle() {
        return "Simple RWT Example";
    } );

When this implementation is registered as an OSGi service, you can access the UI with a web browser:

Screenshot RWT Simple Example

You can check out the example project example.rwt.simple from my rap-helpers repository on github. Please note that for this example to run you need declarative services in your target platform, which are not included in the RAP 1.5M1 target but in the latest nightly build. Also be aware that the new API is still provisional and may change again until the final release.

Kudos to Frank Appel, who contributed the new OSGi integration. He has a more detailed introduction to the new OSGi integration and examples for configuration in his blog. BTW, Frank and me plan to demo the possibilities of this approach in our talk Dynamic web applications with OSGi and RAP at the EclipseCon Europe – vote for it if you’re interested!

  • Josen
    Posted at 1:22 am, September 16, 2011

    I did all the steps except I am using 1.5M1 and registering the service manually.

    context.registerService( Configurator.class.getName(), new SimpleConfigurator() , null );

    And I get the following error:


    Caused by:

    java.lang.IllegalStateException: No ApplicationContext registered.
    at org.eclipse.rwt.internal.engine.ApplicationContextUtil.checkApplicationContextExists(
    at org.eclipse.rwt.internal.engine.ApplicationContextUtil.getInstance(
    at org.eclipse.rwt.internal.engine.RWTFactory.getServiceManager(
    at org.eclipse.rwt.internal.engine.RWTDelegate.handleValidRequest(
    at org.eclipse.rwt.internal.engine.RWTDelegate.doPost(
    at org.eclipse.rwt.internal.engine.RWTDelegate.doGet(
    at javax.servlet.http.HttpServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.eclipse.rap.rwt.osgi.internal.CutOffContextPathWrapper.service(
    at org.mortbay.jetty.servlet.ServletHolder.handle(
    at org.mortbay.jetty.servlet.ServletHandler.handle(
    at org.ops4j.pax.web.service.internal.HttpServiceServletHandler.handle(
    at org.mortbay.jetty.servlet.SessionHandler.handle(
    at org.mortbay.jetty.handler.ContextHandler.handle(
    at org.ops4j.pax.web.service.internal.HttpServiceContext.handle(
    at org.ops4j.pax.web.service.internal.JettyServerHandlerCollection.handle(
    at org.mortbay.jetty.handler.HandlerWrapper.handle(
    at org.mortbay.jetty.Server.handle(
    at org.mortbay.jetty.HttpConnection.handleRequest(
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(
    at org.mortbay.jetty.HttpParser.parseNext(
    at org.mortbay.jetty.HttpParser.parseAvailable(
    at org.mortbay.jetty.HttpConnection.handle(
    at org.mortbay.thread.QueuedThreadPool$

  • Posted at 11:52 am, September 16, 2011

    Hi Josen,

    I just checked out the example.rwt.simple project from Ralf and removed the simpleconfiguration.xml from the manifest and replaced it by an Activator registration that looks like this:

    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: RWT OSGi Example
    Bundle-SymbolicName: example.rwt.simple
    Bundle-Version: 1.0.0.qualifier
    Bundle-ActivationPolicy: lazy
    Bundle-RequiredExecutionEnvironment: J2SE-1.5
    Require-Bundle: org.eclipse.rap.rwt;bundle-version=”1.5.0″
    Bundle-Activator: rwt.simple.Activator
    Import-Package: org.osgi.framework;version=”1.6.0″

    public class Activator implements BundleActivator {

    public void start( BundleContext context ) throws Exception {
    context.registerService( Configurator.class.getName(), new SimpleConfigurator() , null );


    public void stop( BundleContext context ) throws Exception {
    // TODO Auto-generated method stub


    Starting the included launch configuration with the latest nightly build did not show up any problem at all. Maybe you can use the implementation I provided above and look if the problem persists?


  • Josen
    Posted at 5:47 pm, September 17, 2011


    Thanks for your help.

    It looks like it cannot be just any HttpService impl, or jetty. I was using pax webservices. I solve the problem by using the exact versions from the readme:

    0 ACTIVE org.eclipse.osgi_3.8.0.v20110726-1606
    1 ACTIVE org.eclipse.rap.rwt_1.5.0.201108131707
    2 ACTIVE org.eclipse.osgi.services_3.3.0.v20110711-1243
    3 ACTIVE org.mortbay.jetty.server_6.1.23.v201012071420
    4 ACTIVE javax.servlet_2.5.0.v201103041518
    5 ACTIVE org.eclipse.equinox.http.jetty_2.0.100.v20110502
    6 ACTIVE org.mortbay.jetty.util_6.1.23.v201012071420
    7 ACTIVE org.eclipse.equinox.util_1.0.300.v20110502
    8 ACTIVE org.eclipse.equinox.http.servlet_1.1.200.v20110502
    9 ACTIVE example.rwt.simple_1.0.0.qualifier
    10 ACTIVE org.eclipse.rap.rwt.osgi_1.0.0.201108131707
    11 ACTIVE org.eclipse.equinox.ds_1.3.100.v20110705

  • Josen
    Posted at 3:19 am, September 19, 2011


    With this new approach, is it possible to have perspectives and views?

    How would this code look now? Is there a replacement for PlatformUI?

    Display display = PlatformUI.createDisplay();
    WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
    return PlatformUI.createAndRunWorkbench( display, advisor );

  • Posted at 10:21 am, November 17, 2011

    http://localhost:8080/rwt didn’t work for me (as described in the README) so I used http://localhost:8080/simple which is ok