1 16 17 package org.springframework.web.servlet.handler; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.springframework.util.Assert; 23 import org.springframework.web.context.request.WebRequestInterceptor; 24 import org.springframework.web.servlet.HandlerInterceptor; 25 import org.springframework.web.servlet.ModelAndView; 26 27 36 public class WebRequestHandlerInterceptorAdapter implements HandlerInterceptor { 37 38 private final WebRequestInterceptor requestInterceptor; 39 40 41 45 public WebRequestHandlerInterceptorAdapter(WebRequestInterceptor requestInterceptor) { 46 Assert.notNull(requestInterceptor, "WebRequestInterceptor must not be null"); 47 this.requestInterceptor = requestInterceptor; 48 } 49 50 51 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 52 throws Exception { 53 54 this.requestInterceptor.preHandle(new DispatcherServletWebRequest(request)); 55 return true; 56 } 57 58 public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) 59 throws Exception { 60 61 this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request), 62 (modelAndView != null ? modelAndView.getModelMap() : null)); 63 } 64 65 public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) 66 throws Exception { 67 68 this.requestInterceptor.afterCompletion(new DispatcherServletWebRequest(request), ex); 69 } 70 71 } 72 | Popular Tags |