01: /*
02: * Copyright 2002-2005 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.Servlet;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.springframework.web.servlet.HandlerAdapter;
24: import org.springframework.web.servlet.ModelAndView;
25:
26: /**
27: * Adapter to use the Servlet interface with the generic DispatcherServlet.
28: * Calls the Servlet's <code>service</code> method to handle a request.
29: *
30: * <p>Last-modified checking is not explicitly supported: This is typically
31: * handled by the Servlet implementation itself (usually deriving from
32: * the HttpServlet base class).
33: *
34: * <p>This adapter is not activated by default; it needs to be defined as a
35: * bean in the DispatcherServlet context. It will automatically apply to
36: * mapped handler beans that implement the Servlet interface then.
37: *
38: * <p>Note that Servlet instances defined as bean will not receive initialization
39: * and destruction callbacks, unless a special post-processor such as
40: * SimpleServletPostProcessor is defined in the DispatcherServlet context.
41: *
42: * <p><b>Alternatively, consider wrapping a Servlet with Spring's
43: * ServletWrappingController.</b> This is particularly appropriate for
44: * existing Servlet classes, allowing to specify Servlet initialization
45: * parameters etc.
46: *
47: * @author Juergen Hoeller
48: * @since 1.1.5
49: * @see javax.servlet.Servlet
50: * @see javax.servlet.http.HttpServlet
51: * @see SimpleServletPostProcessor
52: * @see org.springframework.web.servlet.mvc.ServletWrappingController
53: */
54: public class SimpleServletHandlerAdapter implements HandlerAdapter {
55:
56: public boolean supports(Object handler) {
57: return (handler instanceof Servlet);
58: }
59:
60: public ModelAndView handle(HttpServletRequest request,
61: HttpServletResponse response, Object handler)
62: throws Exception {
63:
64: ((Servlet) handler).service(request, response);
65: return null;
66: }
67:
68: public long getLastModified(HttpServletRequest request,
69: Object handler) {
70: return -1;
71: }
72:
73: }
|