1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.server; 20 21 import java.io.IOException; 22 23 import javax.servlet.ServletException; 24 import javax.servlet.http.HttpServletRequest; 25 import javax.servlet.http.HttpServletResponse; 26 27 import org.eclipse.jetty.util.annotation.ManagedAttribute; 28 import org.eclipse.jetty.util.annotation.ManagedObject; 29 import org.eclipse.jetty.util.annotation.ManagedOperation; 30 import org.eclipse.jetty.util.component.Destroyable; 31 import org.eclipse.jetty.util.component.LifeCycle; 32 33 /* ------------------------------------------------------------ */ 34 /** A Jetty Server Handler. 35 * 36 * A Handler instance is required by a {@link Server} to handle incoming 37 * HTTP requests. A Handler may: <ul> 38 * <li>Completely generate the HTTP Response</li> 39 * <li>Examine/modify the request and call another Handler (see {@link HandlerWrapper}). 40 * <li>Pass the request to one or more other Handlers (see {@link HandlerCollection}). 41 * </ul> 42 * 43 * Handlers are passed the servlet API request and response object, but are 44 * not Servlets. The servlet container is implemented by handlers for 45 * context, security, session and servlet that modify the request object 46 * before passing it to the next stage of handling. 47 * 48 */ 49 @ManagedObject("Jetty Handler") 50 public interface Handler extends LifeCycle, Destroyable 51 { 52 /* ------------------------------------------------------------ */ 53 /** Handle a request. 54 * @param target The target of the request - either a URI or a name. 55 * @param baseRequest The original unwrapped request object. 56 * @param request The request either as the {@link Request} 57 * object or a wrapper of that request. The {@link HttpChannel#getCurrentHttpChannel()} 58 * method can be used access the Request object if required. 59 * @param response The response as the {@link Response} 60 * object or a wrapper of that request. The {@link HttpChannel#getCurrentHttpChannel()} 61 * method can be used access the Response object if required. 62 * @throws IOException 63 * @throws ServletException 64 */ 65 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) 66 throws IOException, ServletException; 67 68 public void setServer(Server server); 69 70 @ManagedAttribute(value="the jetty server for this handler", readonly=true) 71 public Server getServer(); 72 73 @ManagedOperation(value="destroy associated resources", impact="ACTION") 74 public void destroy(); 75 76 } 77