Thursday, January 28, 2010

Injecting request and response objects of GWT client in Spring.

Hi,


In my last post I had explained how I integrated Spring with GWT by using the external library. Now I had another issue, in which I wanted the HttpSession object in the service class. I had to retrieve some variables from the session object. Since I wasn't extending my service layer class from RemoteServiceServlet I couldn't use the methods to get access to the request and response objects and hence I couldn't get the session object. I discovered that I there were some helper classes in the same external library which could be used and injected using Spring AOP. There is a RequestInjection class which was used  by us as an interceptor to the request.
It was mapped in the spring-servlet file in the following manner.


< bean id="requestSetter" class="org.gwtwidgets.server.spring.RequestInjection" >
        < property name="requestSetterName" value="setRequest"/ >
        < property name="responseSetterName" value="setResponse" / >
    < / bean >
< bean id="testServiceProxy"
          class="org.springframework.aop.framework.ProxyFactoryBean" >
          < property name="target" ref="testService" / >
          < property name="autodetectInterfaces" value="true" / >
          < property name="interceptorNames" >
              < list >
                  < value >requestSetter< / value >
              < / list >
          < / property >
    < / bean >

Wednesday, January 27, 2010

Using Spring with GWT (Google Web Toolkit)

Hi All,
I have been working on the Google web toolkit (GWT) technology version 1.6 lately. We had a task at hand to integrate server side spring technology and use GWT at the client side. GWT is an AJAX based framework developed by google and all the server side calls are processed through AJAX. The catch here is since GWT dispatches only RPC calls to the server. To integrate spring framework, an external library gwt-sl-0.1.5b.jar  was used in which we have a support package for spring integration. This discovery helped us to solve most of out problems. A GWTHandler class was used to handle the RPC requests from the GWT client.
This class is mapped in the spring-servlet file on the server side as follows:


     < bean class="org.gwtwidgets.server.spring.GWTHandler" >
          < property name="mappings" >
              < map >
                      < entry key="/module/myTestModule/test.rpc" 

                                   value-ref="test" / >
              < / map >
          < / property >
       < / bean > 


Prior to using this method, the service classes on the server side used to extend from the RemoteServiceServlet class. But using this mapping I could avoid extending from any classes and hence keeping the class free to extend from any other application specific classes.