public abstract class AbstractRequestHandler extends AbstractResource implements RequestHandler
This class provides an abstract RequestHandler
implementation with reasonable defaults for everything but
RequestHandler.handleRequest(Request, ResponseHandler)
.
A very simple hello world handler could be implemented like this:
class HelloWorldHandler extends AbstractRequestHandler { @Override public ContentChannel handleRequest(Request request, ResponseHandler handler) { ContentWriter writer = ResponseDispatch.newInstance(Response.Status.OK).connectWriter(handler); try { writer.write("Hello World!"); } finally { writer.close(); } return null; } }
DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
Constructor and Description |
---|
AbstractRequestHandler() |
Modifier and Type | Method and Description |
---|---|
void |
handleTimeout(Request request,
ResponseHandler responseHandler)
This method is called by the
Container when a Request that was previously accepted by RequestHandler.handleRequest(Request, ResponseHandler) has timed out. |
currentState, destroy, refer, release, retainCount
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handleRequest
refer, release
public void handleTimeout(Request request, ResponseHandler responseHandler)
RequestHandler
This method is called by the Container
when a Request
that was previously accepted by RequestHandler.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 RequestHandler.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.
handleTimeout
in interface RequestHandler
request
- The Request that has timed out.responseHandler
- The handler to pass the timeout Response
to.Response.dispatchTimeout(ResponseHandler)
Copyright © 2018. All rights reserved.