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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.server;
21 import java.io.IOException;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
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;
35 /* ------------------------------------------------------------ */
36 /** A Jetty Server Handler.
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}).
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.
51 @ManagedObject("Jetty Handler")
52 public interface Handler extends LifeCycle, Destroyable
54 /* ------------------------------------------------------------ */
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 HttpChannel#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 HttpChannel#getCurrentHttpChannel()}
63 * method can be used access the Response object if required.
65 * @throws ServletException
67 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
68 throws IOException, ServletException;
70 public void setServer(Server server);
72 @ManagedAttribute(value="the jetty server for this handler", readonly=true)
73 public Server getServer();
75 @ManagedOperation(value="destroy associated resources", impact="ACTION")
76 public void destroy();