GWT and Spring

From Zanecorpwiki

Jump to: navigation, search

I'm no fan of GWT and I think Spring is more often than not harmful, but there are times when using them together may be warranted, or if not, you're required to anyway. In such cases, you might as well integrate the controllers.

The basic idea is to first direct incoming GWT service calls through org.springframework.web.servlet.DispatcherServlet. The DispatcherServlet sets up the Spring environment, including initializing and configuring any Spring beans, and then hands off control to your own GWTController class which extends the GWT servlet and implements the Spring Controller interface. The call from DispatcherServlet is received through the Spring interface which then invokes the regular GWT methods to pass the request along to your GWT service implementation.

The idea was first together and is fleshed out here. However, the implementation isn't complete for all environments and there are two problems to solve.

First, under some circumstances which I don't fully comprehend (the details being unnecessary to effect the cure), you need to make the GWT/Spring controller "context aware". My unchecked guess is that this is the case when the service implementation accesses the Spring session directly. So, if you implemented the services such that they rely on the first step in the chain to set the beans and never refer to the Spring session directly from the service implementation, you may be able to skip this step.

If that's not the case, or you just want a more robust implementation, you need to make the GWT/Spring controller context aware. Detailed instructions are found in the previous link, but the general is to implement an interface and which will cause the DispatcherServlet pass session context information along.

Second, if you use getThreadLocalRequest in your GWT service implementation, you'll get null. I have a fix for this. I have a fix in my code, but don't have the time to look it up just now. Not 100% sure, but this may be a clue to the problem.

Personal tools