001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.servlet.mvc;
018
019import javax.servlet.http.HttpServletRequest;
020import javax.servlet.http.HttpServletResponse;
021
022import org.springframework.web.HttpRequestHandler;
023import org.springframework.web.servlet.HandlerAdapter;
024import org.springframework.web.servlet.ModelAndView;
025
026/**
027 * Adapter to use the plain {@link org.springframework.web.HttpRequestHandler}
028 * interface with the generic {@link org.springframework.web.servlet.DispatcherServlet}.
029 * Supports handlers that implement the {@link LastModified} interface.
030 *
031 * <p>This is an SPI class, not used directly by application code.
032 *
033 * @author Juergen Hoeller
034 * @since 2.0
035 * @see org.springframework.web.servlet.DispatcherServlet
036 * @see org.springframework.web.HttpRequestHandler
037 * @see LastModified
038 * @see SimpleControllerHandlerAdapter
039 */
040public class HttpRequestHandlerAdapter implements HandlerAdapter {
041
042        @Override
043        public boolean supports(Object handler) {
044                return (handler instanceof HttpRequestHandler);
045        }
046
047        @Override
048        public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
049                        throws Exception {
050
051                ((HttpRequestHandler) handler).handleRequest(request, response);
052                return null;
053        }
054
055        @Override
056        public long getLastModified(HttpServletRequest request, Object handler) {
057                if (handler instanceof LastModified) {
058                        return ((LastModified) handler).getLastModified(request);
059                }
060                return -1L;
061        }
062
063}