01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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: /**
28: * Adapter that implements the Servlet HandlerInterceptor interface
29: * and wraps an underlying WebRequestInterceptor.
30: *
31: * @author Juergen Hoeller
32: * @since 2.0
33: * @see org.springframework.web.context.request.WebRequestInterceptor
34: * @see org.springframework.web.servlet.HandlerInterceptor
35: */
36: public class WebRequestHandlerInterceptorAdapter implements
37: HandlerInterceptor {
38:
39: private final WebRequestInterceptor requestInterceptor;
40:
41: /**
42: * Create a new WebRequestHandlerInterceptorAdapter for the given WebRequestInterceptor.
43: * @param requestInterceptor the WebRequestInterceptor to wrap
44: */
45: public WebRequestHandlerInterceptorAdapter(
46: WebRequestInterceptor requestInterceptor) {
47: Assert.notNull(requestInterceptor,
48: "WebRequestInterceptor must not be null");
49: this .requestInterceptor = requestInterceptor;
50: }
51:
52: public boolean preHandle(HttpServletRequest request,
53: HttpServletResponse response, Object handler)
54: throws Exception {
55:
56: this .requestInterceptor
57: .preHandle(new DispatcherServletWebRequest(request));
58: return true;
59: }
60:
61: public void postHandle(HttpServletRequest request,
62: HttpServletResponse response, Object handler,
63: ModelAndView modelAndView) throws Exception {
64:
65: this .requestInterceptor.postHandle(
66: new DispatcherServletWebRequest(request),
67: (modelAndView != null ? modelAndView.getModelMap()
68: : null));
69: }
70:
71: public void afterCompletion(HttpServletRequest request,
72: HttpServletResponse response, Object handler, Exception ex)
73: throws Exception {
74:
75: this .requestInterceptor.afterCompletion(
76: new DispatcherServletWebRequest(request), ex);
77: }
78:
79: }
|