Some background on how ServletUtils works:
It declares a thread local variable (meaning its value is unique to a
servlet request) in which the SL code stores the current
HttpServletRequest and HttpServletResponse. The GWTSecuredHandler
overrides the default SL behaviour and doesn't set the request and
response in ServletUtils.
May I suggest that you extend the GWTSecuredHandler (not tested) like this:
public class MyGWTSecuredHandler extends GWTSecuredHandler{
@Override
protected Object
getHandlerInternal(HttpServletRequestrequest)throwsException{
ServletUtils.setRequest(request);
return super.getHandlerInternal(request);
I'm using the below code and it works fine for me. I don't recall if
this requires any additional configuration in web.xml or elsewhere but
I don't think so.
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
HttpServletRequest request =
((ServletRequestAttributes)
RequestContextHolder.getRequestAttributes()).getRequest();
Julian's answer (using the RequestContextHolder) is definitely
preferable as it uses Spring's own functionality and does not tie your
service to the SL API - according to the javadocs you should be able to
get the response in addition to the request provided you use Spring 3.0
(some getters seem to be missing in 2.x). As I wrote earlier in this
thread, the reason lies with the GWTSecuredHandler which doesn't
populate ServletUtils.