DWRとSpringApplicationでHttpServletRequestオブジェクトを取得する正しい方法は何でしょうか。次のようにしようとしています。
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();
}
}
}
このメソッドがいずれかのhttpコンテキストを使い果たした場合、メソッドWebContextFactoryは次の警告をログに記録するため、これを求めています。
WARN org.directwebremoting.WebContextFactory:39 - Missing WebContextBuilder. Is DWR setup properly?
このメソッド呼び出しがHttpServletRequest内にあるかどうかを判断するメソッドが欠落している可能性があるため、null値を直接返すことができます。
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;
}
...