View Javadoc

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