Monday, December 10, 2007

Quick solution for Spring & GWT integration

As promised in my last post, I'll describe here how I proceeded to integrate my service bean layer managed by the Spring container with the RPC mechanism offered by GWT.

GWT toolkit offers a custom servlet (RemoteServiceServlet) from which we can inherit in order to let client code calls server-side code asynchronously. The solution I implemented was to create a base Controller which simply extends the Google RemoteServiceServlet. See code below.
(I no longer has access to these files, so I just removed them for now)




By subclassing this new base Controller, all my service-bean classes become now GWT-RPC compatible. This simple solution has some drawback such as adding a compile-time dependency between my service-bean and the Spring framework/GWT, however that is just fine for my specific use-case. More clever solution could also make use of reflection in order to leave your service leaving the service-layer classes free of such dependency, however this will come at a price of more intense processing needs. For those interested see the GWT Server Library initiative.

However for me, this simple solution offered a very convenient caching mechanism to improve performance all client accessing these service-beans. Since I have
some RPC service objects on the server layer for which result are cached to avoid the expensive database access hit. Because these result objects contain long object graphs (a few number of association at various depth level..), I also wished to avoid the GWT serialization process involved at every hit of these cached object graph. To achieve this, I wanted to store the GWT-serialized version
of my result objects instead of the normal de-serialized graph. The cache is planned to refresh itself at regular interval...

All my service-bean achieve this by optionally intercepting the RPC request (i.e. override the method 'processCall') and use the GWT-serialized value when available in cache (see example below).
(I no longer has access to these files, so I just removed them for now)




Martin