Browse Source

WebRequestInterceptor exposes HttpServletResponse through NativeWebRequest (after downcast)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3188 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
2ae5ea3d2e
  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 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,8 +17,8 @@
package org.springframework.web.servlet.handler; package org.springframework.web.servlet.handler;
import java.util.Locale; import java.util.Locale;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.servlet.support.RequestContextUtils;
@ -44,6 +44,15 @@ public class DispatcherServletWebRequest extends ServletWebRequest {
super(request); 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 @Override
public Locale getLocale() { public Locale getLocale() {
return RequestContextUtils.getLocale(getRequest()); return RequestContextUtils.getLocale(getRequest());

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

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
this.requestInterceptor.preHandle(new DispatcherServletWebRequest(request)); this.requestInterceptor.preHandle(new DispatcherServletWebRequest(request, response));
return true; return true;
} }
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws Exception { throws Exception {
this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request), this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request, response),
(modelAndView != null && !modelAndView.wasCleared() ? modelAndView.getModelMap() : null)); (modelAndView != null && !modelAndView.wasCleared() ? modelAndView.getModelMap() : null));
} }
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception { throws Exception {
this.requestInterceptor.afterCompletion(new DispatcherServletWebRequest(request), ex); this.requestInterceptor.afterCompletion(new DispatcherServletWebRequest(request, response), ex);
} }
} }

Loading…
Cancel
Save