WebRequestInterceptor exposes HttpServletResponse through NativeWebRequest (after downcast)

This commit is contained in:
Juergen Hoeller 2010-03-30 09:21:09 +00:00
parent 9cecaa769e
commit 81e81ce77c
2 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@
package org.springframework.web.servlet.handler;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.servlet.support.RequestContextUtils;
@ -44,6 +44,15 @@ public class DispatcherServletWebRequest extends ServletWebRequest {
super(request);
}
/**
* Create a new DispatcherServletWebRequest instance for the given request and response.
* @param request current HTTP request
* @param request current HTTP response
*/
public DispatcherServletWebRequest(HttpServletRequest request, HttpServletResponse response) {
super(request, response);
}
@Override
public Locale getLocale() {
return RequestContextUtils.getLocale(getRequest());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -51,21 +51,21 @@ public class WebRequestHandlerInterceptorAdapter implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
this.requestInterceptor.preHandle(new DispatcherServletWebRequest(request));
this.requestInterceptor.preHandle(new DispatcherServletWebRequest(request, response));
return true;
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws Exception {
this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request),
this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request, response),
(modelAndView != null && !modelAndView.wasCleared() ? modelAndView.getModelMap() : null));
}
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
this.requestInterceptor.afterCompletion(new DispatcherServletWebRequest(request), ex);
this.requestInterceptor.afterCompletion(new DispatcherServletWebRequest(request, response), ex);
}
}