I am wondering what is the correct way of getting HttpServletRequest object in DWR and in Spring Application - I am trying to do as follows:
private HttpServletRequest getRequest() {
ServletRequestAttributes servletAttributes =
(ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
// this is Spring application's DispatcherServlet call
if (servletAttributes != null) {
return servletAttributes.getRequest();
} else {
if (WebContextFactory.get() == null) {
// non-HttpRequest call
return null;
} else {
// dwr call
return WebContextFactory.get().getHttpServletRequest();
}
}
}
I am asking this because when this method is run out of any of http contexts, the methods WebContextFactory logs following warning:
WARN org.directwebremoting.WebContextFactory:39 - Missing WebContextBuilder. Is DWR setup properly?
I am probably missing method which would tell if this method call is within HttpServletRequest, so I could return directly null value:
private HttpServletRequest getRequest() {
// something like this would be ideal:
if (!ServletContextFactory.isInServletContext()) {
// method was not called from ServletRequest, so there is none to be found
return null;
}
...