Interface Handler
- All Superinterfaces:
 Destroyable, Invocable, LifeCycle, Request.Handler
- All Known Subinterfaces:
 Handler.Collection, Handler.Container, Handler.Singleton, HandlerContainer
- All Known Implementing Classes:
 AbstractHandler, AbstractHandlerContainer, BufferedResponseHandler, CompressionHandler, ConditionalHandler, ConditionalHandler.Abstract, ConditionalHandler.DontHandle, ConditionalHandler.ElseNext, ConditionalHandler.Reject, ConditionalHandler.SkipNext, ConnectHandler, ConstraintSecurityHandler, ConstraintSecurityHandler, ContextHandler, ContextHandler.CoreContextHandler, ContextHandler.CoreContextHandler, ContextHandlerCollection, CoreAppContext, CrossOriginHandler, DebugHandler, DefaultHandler, DelayedHandler, DoSHandler, DoSHandler.DelayedRejectHandler, DumpHandler, EagerContentHandler, EagerFormHandler, EagerFormHandler, EchoHandler, EchoHandler.Buffered, EchoHandler.BufferedAsync, EchoHandler.Reactive, EchoHandler.Stream, EventsHandler, FastCGIProxyHandler, GracefulHandler, GzipHandler, Handler.Abstract, Handler.Abstract.NonBlocking, Handler.AbstractContainer, Handler.Sequence, Handler.Wrapper, HotSwapHandler, HttpSpiContextHandler, IdleTimeoutHandler, InetAccessHandler, LatencyRecordingHandler, MovedContextHandler, PathMappingsHandler, PathMappingsHandler.NoContext, ProxyHandler, ProxyHandler.Forward, ProxyHandler.Reverse, QoSHandler, ResourceHandler, ResourceHandler.ResourceContext, RewriteHandler, SecuredRedirectHandler, SecurityHandler, SecurityHandler.PathMapped, Server, ServletContextHandler, ServletContextHandler, ServletHandler, ServletHandler, SessionHandler, SessionHandler, SessionHandler, ShutdownHandler, SizeLimitHandler, SizeLimitHandler, StateTrackingHandler, StaticAppContext, StatisticsHandler, StatisticsHandler.MinimumDataRateHandler, ThreadLimitHandler, TryPathsHandler, WebAppContext, WebAppContext, WebSocketUpgradeHandler, WebSocketUpgradeHandler
A Jetty component that handles HTTP requests, of any version (HTTP/1.1, HTTP/2 or HTTP/3).
A Handler is a Request.Handler with the addition of LifeCycle
behaviours, plus variants that allow organizing Handlers as a tree structure.
Handlers may wrap the Request, Response and/or Callback and
then forward the wrapped instances to their children, so that they see a modified request;
and/or to intercept the read of the request content; and/or intercept the generation of the
response; and/or to intercept the completion of the callback.
A Handler is an Invocable and implementations must respect
the Invocable.InvocationType they declare within calls to
Request.Handler.handle(Request, Response, Callback).
A minimal tree structure could be:
Server
`- YourCustomHandler
A more sophisticated tree structure:
Server
`- GzipHandler
   `- ContextHandlerCollection
      +- ContextHandler (contextPath="/user")
      |  `- YourUserHandler
      |- ContextHandler (contextPath="/admin")
      |  `- YourAdminHandler
      `- DefaultHandler
A simple Handler implementation could be:
class SimpleHandler extends Handler.Abstract.NonBlocking
{
    @Override
    public boolean handle(Request request, Response response, Callback callback)
    {
        // Implicitly sends a 200 OK response with no content.
        callback.succeeded();
        return true;
    }
}
A more sophisticated example of a Handler that decides whether to handle
requests based on their URI path:
class YourHelloHandler extends Handler.Abstract.NonBlocking
{
    @Override
    public boolean handle(Request request, Response response, Callback callback)
    {
        if (request.getHttpURI().getPath().startsWith("/yourPath"))
        {
            // The request is for this Handler
            response.setStatus(200);
            // The callback is completed when the write is completed.
            response.write(true, UTF_8.encode("hello"), callback);
            return true;
        }
        return false;
    }
}
An example of a Handler that decides whether to pass the request to
a child:
class ConditionalHandler extends Handler.Wrapper
{
    @Override
    public boolean handle(Request request, Response response, Callback callback)
    {
        if (request.getHttpURI().getPath().startsWith("/yourPath")
            return super.handle(request, response, callback);
        if (request.getHttpURI().getPath().startsWith("/wrong"))
        {
            Response.writeError(request, response, callback, HttpStatus.BAD_REQUEST_400);
            return true;
        }
        return false;
    }
}
- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAn abstract implementation ofHandlerthat is aContainerLifeCycle.static classAHandler.Abstractthat implementsHandler.Container.static interfaceAHandler.Containerthat can contain multiple otherHandlers.static interfaceAHandlerthat contains one or more otherHandlers.static classAHandler.Containerthat contains an ordered list of childrenHandlers whoseRequest.Handler.handle(Request, Response, Callback)method is invoked in sequence on each child until a child returnstrue.static interfaceAHandler.Containerthat can contain one single otherHandler.static classAn implementation ofHandler.Singleton, which is aHandler.Containerthat wraps one single otherHandler.Nested classes/interfaces inherited from interface Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.TaskNested classes/interfaces inherited from interface LifeCycle
LifeCycle.ListenerNested classes/interfaces inherited from interface Request.Handler
Request.Handler.AbortException - 
Field Summary
Fields inherited from interface Invocable
__nonBlocking, NOOP - 
Method Summary
Methods inherited from interface Destroyable
destroyMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stopMethods inherited from interface Request.Handler
getInvocationType, handle 
- 
Method Details
- 
getServer
@ManagedAttribute(value="The Server instance associated to this Handler", readonly=true) Server getServer()- Returns:
 - the 
Serverassociated with thisHandler 
 - 
setServer
Set theServerto associate to thisHandler.- Parameters:
 server- theServerto associate to thisHandler
 - 
optionsMethodHandled
static boolean optionsMethodHandled(String allowedMethods, Request request, Response response, Callback callback) Utility method to handle OPTIONS method- Parameters:
 allowedMethods- The allowed methods ornullfor "GET,HEAD,OPTIONS"request- The requestresponse- The responsecallback- The callback- Returns:
 trueif the request is handled
 
 -