Interface HttpResponseHandler<IntermediateType,FinalType>
-
- All Known Implementing Classes:
BytesFullResponseHandler
,FrameFileHttpResponseHandler
,InputStreamFullResponseHandler
,InputStreamResponseHandler
,ObjectOrErrorResponseHandler
,SequenceInputStreamResponseHandler
,StatusResponseHandler
,StringFullResponseHandler
public interface HttpResponseHandler<IntermediateType,FinalType>
A handler for an HTTP request. The ClientResponse object passed around is used to store state between further chunks and indicate when it is safe to hand the object back to the caller. If the response is chunked, the ClientResponse object returned from handleResponse will be passed in as the first argument to handleChunk(). If the ClientResponse object is marked as finished, that indicates that the object stored is safe to hand off to the caller. This is most often done either from the done() method after all content has been processed or from the initial handleResponse method to indicate that the object is thread-safe and aware that it might be accessed before all chunks come back. Note: if you return a finished ClientResponse object from anything other than the done() method, IntermediateType must be castable to FinalType This handler can exert backpressure by returning a response with "continueReading" set to false from handleResponse() or handleChunk(). In this case, the HTTP client will stop reading soon thereafter. It may not happen immediately, so be prepared for more handleChunk() calls to happen. To resume reads, call resume() on the TrafficCop provided by handleResponse() with a chunk number at least as high as the one provided by the handleChunk() call from which you returned a suspend-reading response. If you are resuming reads after suspending them from handleResponse(), use 0 for the chunk number.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
HttpResponseHandler.TrafficCop
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ClientResponse<FinalType>
done(ClientResponse<IntermediateType> clientResponse)
Called after the final handleResponse() or handleChunk() call, signifying that no more data will arrive.void
exceptionCaught(ClientResponse<IntermediateType> clientResponse, Throwable e)
ClientResponse<IntermediateType>
handleChunk(ClientResponse<IntermediateType> clientResponse, org.jboss.netty.handler.codec.http.HttpChunk chunk, long chunkNum)
Called for chunked responses, indicating another HttpChunk has arrived.ClientResponse<IntermediateType>
handleResponse(org.jboss.netty.handler.codec.http.HttpResponse response, HttpResponseHandler.TrafficCop trafficCop)
Handles the initial HttpResponse object that comes back from Netty.
-
-
-
Method Detail
-
handleResponse
ClientResponse<IntermediateType> handleResponse(org.jboss.netty.handler.codec.http.HttpResponse response, HttpResponseHandler.TrafficCop trafficCop)
Handles the initial HttpResponse object that comes back from Netty.- Parameters:
response
- response from NettytrafficCop
- flow controller, allows resuming suspended reads- Returns:
- response that may be "finished" or "unfinished".
-
handleChunk
ClientResponse<IntermediateType> handleChunk(ClientResponse<IntermediateType> clientResponse, org.jboss.netty.handler.codec.http.HttpChunk chunk, long chunkNum)
Called for chunked responses, indicating another HttpChunk has arrived.- Parameters:
clientResponse
- last response returned by the prior handleResponse() or handleChunk()chunk
- the new chunk of datachunkNum
- the sequence number of this chunk (increases monotonically)- Returns:
- response that may be "finished" or "unfinished".
-
done
ClientResponse<FinalType> done(ClientResponse<IntermediateType> clientResponse)
Called after the final handleResponse() or handleChunk() call, signifying that no more data will arrive.- Parameters:
clientResponse
- last response returned by handleResponse() or handleChunk()- Returns:
- response containing an object to hand back to the caller. It must be a "finished" response.
-
exceptionCaught
void exceptionCaught(ClientResponse<IntermediateType> clientResponse, Throwable e)
-
-