View Javadoc

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.server.handler.HandlerCollection;
28  import org.eclipse.jetty.server.handler.HandlerWrapper;
29  import org.eclipse.jetty.util.component.Destroyable;
30  import org.eclipse.jetty.util.component.LifeCycle;
31  
32  /* ------------------------------------------------------------ */
33  /** A Jetty Server Handler.
34   * 
35   * A Handler instance is required by a {@link Server} to handle incoming
36   * HTTP requests.  A Handler may: <ul>
37   * <li>Completely generate the HTTP Response</li>
38   * <li>Examine/modify the request and call another Handler (see {@link HandlerWrapper}).
39   * <li>Pass the request to one or more other Handlers (see {@link HandlerCollection}).
40   * </ul>
41   * 
42   * Handlers are passed the servlet API request and response object, but are 
43   * not Servlets.  The servlet container is implemented by handlers for 
44   * context, security, session and servlet that modify the request object 
45   * before passing it to the next stage of handling.
46   * 
47   */
48  public interface Handler extends LifeCycle, Destroyable
49  {
50      /* ------------------------------------------------------------ */
51      /** Handle a request.
52       * @param target The target of the request - either a URI or a name.
53       * @param baseRequest The original unwrapped request object.
54       * @param request The request either as the {@link Request}
55       * object or a wrapper of that request. The {@link AbstractHttpConnection#getCurrentConnection()} 
56       * method can be used access the Request object if required.
57       * @param response The response as the {@link Response}
58       * object or a wrapper of that request. The {@link AbstractHttpConnection#getCurrentConnection()} 
59       * method can be used access the Response object if required.
60       * @throws IOException
61       * @throws ServletException
62       */
63      public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
64          throws IOException, ServletException;
65      
66      public void setServer(Server server);
67      public Server getServer();
68      
69      public void destroy();
70      
71  }
72