Package com.yahoo.container.jdisc
Class ThreadedHttpRequestHandler
- java.lang.Object
-
- com.yahoo.jdisc.AbstractResource
-
- com.yahoo.jdisc.handler.AbstractRequestHandler
-
- com.yahoo.container.jdisc.ThreadedRequestHandler
-
- com.yahoo.container.jdisc.ThreadedHttpRequestHandler
-
- All Implemented Interfaces:
HttpRequestHandler
,com.yahoo.jdisc.handler.RequestHandler
,com.yahoo.jdisc.SharedResource
- Direct Known Subclasses:
AccessLogRequestHandler
,FilterBackingRequestHandler
,HttpHandlerBase
,LoggingRequestHandler
,LogHandler
,MockService
,RestApiRequestHandler
,VipStatusHandler
public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler implements HttpRequestHandler
A simple HTTP request handler, using theHttpRequest
andHttpResponse
classes. Users need to override thehandle(HttpRequest)
method in this class and theHttpResponse.render(java.io.OutputStream)
method.- Author:
- hmusum, Steinar Knutsen, bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ThreadedHttpRequestHandler.Context
static class
ThreadedHttpRequestHandler.LazyContentChannel
A content channel which will return the header and create the proper channel the first time content data needs to be written to it.
-
Field Summary
Fields Modifier and Type Field Description static String
CONTENT_TYPE
protected Logger
log
Logger for subclasses-
Fields inherited from class com.yahoo.container.jdisc.ThreadedRequestHandler
metric
-
-
Constructor Summary
Constructors Constructor Description ThreadedHttpRequestHandler(ThreadedHttpRequestHandler.Context context)
ThreadedHttpRequestHandler(Executor executor)
ThreadedHttpRequestHandler(Executor executor, com.yahoo.jdisc.Metric metric)
ThreadedHttpRequestHandler(Executor executor, com.yahoo.jdisc.Metric metric, boolean allowAsyncResponse)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addDateHeader(HttpResponse httpResponse, long startTime)
protected HttpRequest
asHttpRequest(com.yahoo.jdisc.Request request)
protected LoggingCompletionHandler
createLoggingCompletionHandler(long startTime, long renderStartTime, HttpResponse response, HttpRequest httpRequest, ContentChannelOutputStream rendererWiring)
Override this to implement custom access logging.abstract HttpResponse
handle(HttpRequest request)
Override this to implement a synchronous style handler.HttpResponse
handle(HttpRequest request, com.yahoo.jdisc.handler.ContentChannel channel)
Override this rather than handle(request) to be able to write to the channel before returning from this method.void
handleRequest(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.BufferedContentChannel requestContent, com.yahoo.jdisc.handler.ResponseHandler responseHandler)
static ThreadedHttpRequestHandler.Context
testContext()
-
Methods inherited from class com.yahoo.container.jdisc.ThreadedRequestHandler
executor, getRequestType, getTimeout, handleRequest, writeErrorResponseOnOverload
-
Methods inherited from class com.yahoo.jdisc.AbstractResource
currentState, destroy, refer, refer, release, retainCount
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.yahoo.container.jdisc.HttpRequestHandler
requestHandlerSpec
-
-
-
-
Field Detail
-
CONTENT_TYPE
public static final String CONTENT_TYPE
- See Also:
- Constant Field Values
-
log
protected final Logger log
Logger for subclasses
-
-
Constructor Detail
-
ThreadedHttpRequestHandler
public ThreadedHttpRequestHandler(Executor executor)
-
ThreadedHttpRequestHandler
@Inject public ThreadedHttpRequestHandler(Executor executor, com.yahoo.jdisc.Metric metric)
-
ThreadedHttpRequestHandler
public ThreadedHttpRequestHandler(ThreadedHttpRequestHandler.Context context)
-
ThreadedHttpRequestHandler
public ThreadedHttpRequestHandler(Executor executor, com.yahoo.jdisc.Metric metric, boolean allowAsyncResponse)
-
-
Method Detail
-
handle
public abstract HttpResponse handle(HttpRequest request)
Override this to implement a synchronous style handler.- Parameters:
request
- incoming HTTP request- Returns:
- a valid HTTP response for presentation to the user
-
handle
public HttpResponse handle(HttpRequest request, com.yahoo.jdisc.handler.ContentChannel channel)
Override this rather than handle(request) to be able to write to the channel before returning from this method. This default implementation calls handle(request)
-
handleRequest
public final void handleRequest(com.yahoo.jdisc.Request request, com.yahoo.jdisc.handler.BufferedContentChannel requestContent, com.yahoo.jdisc.handler.ResponseHandler responseHandler)
- Specified by:
handleRequest
in classThreadedRequestHandler
-
addDateHeader
protected void addDateHeader(HttpResponse httpResponse, long startTime)
-
createLoggingCompletionHandler
protected LoggingCompletionHandler createLoggingCompletionHandler(long startTime, long renderStartTime, HttpResponse response, HttpRequest httpRequest, ContentChannelOutputStream rendererWiring)
Override this to implement custom access logging.- Parameters:
startTime
- execution startrenderStartTime
- start of output renderingresponse
- the response which the log entry regardshttpRequest
- the incoming HTTP requestrendererWiring
- the stream the rendered response is written to, used for fetching length of rendered response
-
asHttpRequest
protected HttpRequest asHttpRequest(com.yahoo.jdisc.Request request)
-
testContext
public static ThreadedHttpRequestHandler.Context testContext()
-
-