Interface RequestHandler

All Superinterfaces:
SharedResource
All Known Subinterfaces:
ClientProvider, DelegatedRequestHandler
All Known Implementing Classes:
AbstractClientProvider, AbstractRequestHandler, NonWorkingClientProvider, NonWorkingRequestHandler, ThreadedRequestHandler

public interface RequestHandler extends SharedResource
This interface defines a component that is capable of acting as a handler for a Request. To activate a RequestHandler it must be bound to a UriPattern within a ContainerBuilder, and that builder must be activated.
Author:
Simon Thoresen Hult
  • Method Details

    • handleRequest

      ContentChannel handleRequest(Request request, ResponseHandler handler)

      This method will process the given Request and return a ContentChannel into which the caller can write the Request's content. For every call to this method, the implementation must call the provided ResponseHandler exactly once.

      Notice that unless this method throws an Exception, a reference to the currently active Container instance is kept internally until ResponseHandler.handleResponse(Response) has been called. This ensures that the configured environment of the Request is stable throughout its lifetime. Failure to call back with a Response will prevent the release of that reference, and therefore prevent the corresponding Container from ever shutting down. The requirement to call ResponseHandler.handleResponse(Response) is regardless of any subsequent errors that may occur while working with the returned ContentChannel.

      Parameters:
      request - The Request to handle.
      handler - The handler to pass the corresponding Response to.
      Returns:
      The ContentChannel to write the Request content to. Notice that the ContentChannel itself also holds a Container reference, so failure to close this will prevent the Container from ever shutting down.
    • handleTimeout

      void handleTimeout(Request request, ResponseHandler handler)

      This method is called by the Container when a Request that was previously accepted by handleRequest(Request, ResponseHandler) has timed out. If the Request has no timeout (i.e. Request.getTimeout(TimeUnit) returns null), then this method is never called.

      The given ResponseHandler is the same ResponseHandler that was initially passed to the handleRequest(Request, ResponseHandler) method, and it is guarded by a volatile boolean so that only the first call to ResponseHandler.handleResponse(Response) is actually passed on. This means that you do NOT need to manage the ResponseHandlers yourself to prevent a late Response from calling the same ResponseHandler.

      Notice that you MUST call ResponseHandler.handleResponse(Response) as a reaction to having this method invoked. Failure to do so will prevent the Container from ever shutting down.

      Parameters:
      request - The Request that has timed out.
      handler - The handler to pass the timeout Response to.
      See Also: