Skip to main content

Thoughts on GWT & Spring

I recently got involved in a project that used GWT and Spring. One of the first things that struck me was the lack of support for Dependency injection frameworks in GWT. So we had to come up with a Spring controller that looked similar to this
public class SpringAwareGWTService extends RemoteServiceServlet implements Controller {
private ThreadLocal servletContext = new ThreadLocal();
public final ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
servletContext.set(request.getSession().getServletContext());
doPost(request, response);
servletContext.set(null);
return null;
}

public ServletContext getServletContext() {
return servletContext.get();
}
}

Here, what we have done is create a spring controller that is also a GWT remote servlet. Only thing to note is that the GWT remote servlet was never intented to serve as a controller. Also we will force spring to accept the response provided by the servlet by returning null from the method. So we are in essence faking the servlet container in the spring controller here. I could have just copied the contents of the RemoteServiceServlet. But that would be duplicating the implementation of the GWT code.

Comments

  1. That is some sweet stuff--looks like exactly what I need to merge our worlds. Thanks for taking the time to post!

    ReplyDelete

Post a Comment

Popular posts from this blog

Case of the missing timezone

Whenever I try to connect to a Oracle 10g Database on my machine, I encountered this error message: ORA-01882: timezone region not found. This was true for SQl plus as well as while connecting using JDBC. The problem was Oracle 10g did not have "Asia/Kolkata" as a timezone region in the V$TIMEZONE_NAMES view. My machine however was configured to use the above timezone. When I changed the timezone to "Asia/Calcutta" on my machine, things started working fine. Little did the residents of Kolkata realize that changing the name of their city from Calcutta to Kolkata would have such implications!!! While most software has already started using the new name along with the old name, there are some old software that still does not support the new name. Of course, we can configure oracle to use the new name as well..