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.lang.Nullable; 023import org.springframework.web.HttpRequestHandler; 024import org.springframework.web.servlet.HandlerAdapter; 025import org.springframework.web.servlet.ModelAndView; 026 027/** 028 * Adapter to use the plain {@link org.springframework.web.HttpRequestHandler} 029 * interface with the generic {@link org.springframework.web.servlet.DispatcherServlet}. 030 * Supports handlers that implement the {@link LastModified} interface. 031 * 032 * <p>This is an SPI class, not used directly by application code. 033 * 034 * @author Juergen Hoeller 035 * @since 2.0 036 * @see org.springframework.web.servlet.DispatcherServlet 037 * @see org.springframework.web.HttpRequestHandler 038 * @see LastModified 039 * @see SimpleControllerHandlerAdapter 040 */ 041public class HttpRequestHandlerAdapter implements HandlerAdapter { 042 043 @Override 044 public boolean supports(Object handler) { 045 return (handler instanceof HttpRequestHandler); 046 } 047 048 @Override 049 @Nullable 050 public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) 051 throws Exception { 052 053 ((HttpRequestHandler) handler).handleRequest(request, response); 054 return null; 055 } 056 057 @Override 058 public long getLastModified(HttpServletRequest request, Object handler) { 059 if (handler instanceof LastModified) { 060 return ((LastModified) handler).getLastModified(request); 061 } 062 return -1L; 063 } 064 065}