Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts

Tuesday, April 6, 2010

GWT Http request handling using Spring

Hi,
In a GWT based project we had a "login" mechanism which needed https protocol to be used. As GWT provides convienient ways of doing the same by using RequestBuilder class. We were using Spring framework at our server side. For handling GWT - RPC requests we were using the GWTHandler as mentioned in one of my previous posts GWT with Spring.
But now the issue was how to integrate https based requests into the project and into Spring. This was required because all the dependencies were being injected through spring. We figured out a simple solution; all the servlets that were extending from HttpServlet now were now extending from an abstract custom servlet class. This class was implementing the Spring mvc's Controller interface and also had one abstract method containing HttpRequest and HttpResponse objects as arguements. All the processing was done in this method. The handle request method returned a null and all the response was written in the response header. Since we had 2 different ways of hitting the server. The following mapping was added into the myapp-servlet.xml file.
  < !-- Handler mappings for GWT - RPC calls -- >
     < bean class="org.gwtwidgets.server.spring.GWTHandler" >
          < property name="mappings" >
              < map >
                  < entry key="/myApp/myAppService.rpc"  
                              value-ref="myAppRpcService" / >
              < / map >
          < / property >
     < / bean >
  
    < !-- Handler mappings for GWT - Http calls -- >
    < bean  class="org.springframework.
                      web.servlet.handler.SimpleUrlHandlerMapping" >
        < property name="mappings" >
            < props >
                < prop key="/myApp/login.rpc">myAppLogin < / prop >
            < / props >
        < / property >
    < / bean >

Needless to say that myAppRpcService and myAppLogin are the bean id's of beans defined in the spring context file.

I hope this post will be helpful to those who are trying to integrate gwt with spring.

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.