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