001/* 002 * Copyright 2002-2014 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; 018 019import java.io.IOException; 020import javax.servlet.ServletException; 021import javax.servlet.http.HttpServletRequest; 022import javax.servlet.http.HttpServletResponse; 023 024/** 025 * Plain handler interface for components that process HTTP requests, 026 * analogous to a Servlet. Only declares {@link javax.servlet.ServletException} 027 * and {@link java.io.IOException}, to allow for usage within any 028 * {@link javax.servlet.http.HttpServlet}. This interface is essentially the 029 * direct equivalent of an HttpServlet, reduced to a central handle method. 030 * 031 * <p>The easiest way to expose an HttpRequestHandler bean in Spring style 032 * is to define it in Spring's root web application context and define 033 * an {@link org.springframework.web.context.support.HttpRequestHandlerServlet} 034 * in {@code web.xml}, pointing to the target HttpRequestHandler bean 035 * through its {@code servlet-name} which needs to match the target bean name. 036 * 037 * <p>Supported as a handler type within Spring's 038 * {@link org.springframework.web.servlet.DispatcherServlet}, being able 039 * to interact with the dispatcher's advanced mapping and interception 040 * facilities. This is the recommended way of exposing an HttpRequestHandler, 041 * while keeping the handler implementations free of direct dependencies 042 * on a DispatcherServlet environment. 043 * 044 * <p>Typically implemented to generate binary responses directly, 045 * with no separate view resource involved. This differentiates it from a 046 * {@link org.springframework.web.servlet.mvc.Controller} within Spring's Web MVC 047 * framework. The lack of a {@link org.springframework.web.servlet.ModelAndView} 048 * return value gives a clearer signature to callers other than the 049 * DispatcherServlet, indicating that there will never be a view to render. 050 * 051 * <p>As of Spring 2.0, Spring's HTTP-based remote exporters, such as 052 * {@link org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter} 053 * and {@link org.springframework.remoting.caucho.HessianServiceExporter}, 054 * implement this interface rather than the more extensive Controller interface, 055 * for minimal dependencies on Spring-specific web infrastructure. 056 * 057 * <p>Note that HttpRequestHandlers may optionally implement the 058 * {@link org.springframework.web.servlet.mvc.LastModified} interface, 059 * just like Controllers can, <i>provided that they run within Spring's 060 * DispatcherServlet</i>. However, this is usually not necessary, since 061 * HttpRequestHandlers typically only support POST requests to begin with. 062 * Alternatively, a handler may implement the "If-Modified-Since" HTTP 063 * header processing manually within its {@code handle} method. 064 * 065 * @author Juergen Hoeller 066 * @since 2.0 067 * @see org.springframework.web.context.support.HttpRequestHandlerServlet 068 * @see org.springframework.web.servlet.DispatcherServlet 069 * @see org.springframework.web.servlet.ModelAndView 070 * @see org.springframework.web.servlet.mvc.Controller 071 * @see org.springframework.web.servlet.mvc.LastModified 072 * @see org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter 073 * @see org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter 074 * @see org.springframework.remoting.caucho.HessianServiceExporter 075 * @see org.springframework.remoting.caucho.BurlapServiceExporter 076 */ 077public interface HttpRequestHandler { 078 079 /** 080 * Process the given request, generating a response. 081 * @param request current HTTP request 082 * @param response current HTTP response 083 * @throws ServletException in case of general errors 084 * @throws IOException in case of I/O errors 085 */ 086 void handleRequest(HttpServletRequest request, HttpServletResponse response) 087 throws ServletException, IOException; 088 089}