Tuesday, 18 September 2007

GWT and OSGi

I decided I would try to build a GWT app and deploy it in my OSGi container using the Http service.

Deploying GWT as a client only app was straight forward enough. I converted my Eclipse project to an OSGi bundle in the usual way and created an Activator which then created a ServiceTracker and Customiser for the HttpService. In my customiser I register the location of the GWT files and it just works. Great!

So I decided to take the next step and deploy a client/server GWT application.

At first I couldn't work out what was going on. My server side class which extended RemoteServiceServlet was being called (I had overridden the service method to make sure) but nothing appeared to be happening and my client was reporting an error on the server. Everything was working fine through hosted mode, of course.

Eventually I discovered it is because in RemoteServiceServlet there is a call to request.getContextPath() which is a Servlet 2.2 method. OSGi only supports the 2.1 specification and the framework I am using simply throws a ServletException when calls to Servlet 2.2 methods are made. So I copied the code of RemoteServiceServlet and created "OSGiRemoteServiceServlet" then replaced the call to request.getContextPath() with the 2.1 equivalent of request.getRequestURI(). This fixed the problem and my GWT app now runs fine through my OSGi container which is fantastic.

Hopefully, I won't run in to any more Servlet Spec 2.1 issues, but if things don't work as expected, especially compared to hosted mode, that'll be the first thing I check!


amuse said...

Hi Chris,

Nice work. Which release of GWT did you use ?

I tried what you managed to do by using the very last release of GWT 1.4.x, but your RPC approach does not work.

Have you any suggestion about this ?

Best regards,


Chris Brind said...

Hi Alain,

To be honest, I gave up with GWT when I started learning Flex. Since then I have built a platform for modular RIAs based on OSGi and Flex. You can download an alpha version of it here: