Browse Source

WebRequestInterceptor exposes HttpServletResponse through NativeWebRequest (after downcast)

pull/23217/head
Juergen Hoeller 15 years ago
parent
commit
81e81ce77c
  1. 13
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/DispatcherServletWebRequest.java
  2. 8
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java

13
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/DispatcherServletWebRequest.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -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());

8
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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);
}
}

Loading…
Cancel
Save