Package org.apache.http.nio.protocol
Class AbstractAsyncResponseConsumer<T>
java.lang.Object
org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.http.concurrent.Cancellable,HttpAsyncResponseConsumer<T>
- Direct Known Subclasses:
BasicAsyncResponseConsumer
public abstract class AbstractAsyncResponseConsumer<T>
extends Object
implements HttpAsyncResponseConsumer<T>
Abstract
HttpAsyncResponseConsumer implementation that relieves its
subclasses from having to manage internal state and provides a number of protected
event methods that they need to implement.- Since:
- 4.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract TbuildResult(org.apache.http.protocol.HttpContext context) Invoked to generate a result object from the received HTTP response message.final booleancancel()final voidclose()final voidconsumeContent(ContentDecoder decoder, IOControl ioControl) UseonContentReceived(ContentDecoder, IOControl)instead.final voidInvoked to signal that the response processing terminated abnormally.protected org.apache.http.entity.ContentTypegetContentType(org.apache.http.HttpEntity entity) Returns an exception in case of an abnormal termination.Returns a result of the response processing, when available.booleanisDone()Determines whether or not the response processing completed.protected voidonClose()Invoked when the consumer is being closed.protected abstract voidonContentReceived(ContentDecoder decoder, IOControl ioControl) Invoked to process a chunk of content from theContentDecoder.protected abstract voidonEntityEnclosed(org.apache.http.HttpEntity entity, org.apache.http.entity.ContentType contentType) Invoked if the response message encloses a content entity.protected abstract voidonResponseReceived(org.apache.http.HttpResponse response) Invoked when a HTTP response message is received.protected abstract voidInvoked to release all system resources currently allocated.final voidresponseCompleted(org.apache.http.protocol.HttpContext context) UsebuildResult(HttpContext)instead.final voidresponseReceived(org.apache.http.HttpResponse response) UseonResponseReceived(HttpResponse)instead.
-
Constructor Details
-
AbstractAsyncResponseConsumer
public AbstractAsyncResponseConsumer()
-
-
Method Details
-
onResponseReceived
protected abstract void onResponseReceived(org.apache.http.HttpResponse response) throws org.apache.http.HttpException, IOException Invoked when a HTTP response message is received. Please note that theonContentReceived(ContentDecoder, IOControl)method will be invoked only if the response messages has a content entity enclosed.- Parameters:
response- HTTP response message.- Throws:
org.apache.http.HttpException- in case of HTTP protocol violationIOException- in case of an I/O error
-
onContentReceived
protected abstract void onContentReceived(ContentDecoder decoder, IOControl ioControl) throws IOException Invoked to process a chunk of content from theContentDecoder. TheIOControlinterface can be used to suspend input events if the consumer is temporarily unable to consume more content.The consumer can use the
ContentDecoder.isCompleted()method to find out whether or not the message content has been fully consumed.- Parameters:
decoder- content decoder.ioControl- I/O control of the underlying connection.- Throws:
IOException- in case of an I/O error
-
onEntityEnclosed
protected abstract void onEntityEnclosed(org.apache.http.HttpEntity entity, org.apache.http.entity.ContentType contentType) throws IOException Invoked if the response message encloses a content entity.- Parameters:
entity- HTTP entitycontentType- expected content type.- Throws:
IOException- in case of an I/O error
-
buildResult
Invoked to generate a result object from the received HTTP response message.- Parameters:
context- HTTP context.- Returns:
- result of the response processing.
- Throws:
Exception- in case of an abnormal termination.
-
releaseResources
protected abstract void releaseResources()Invoked to release all system resources currently allocated. -
onClose
Invoked when the consumer is being closed.- Throws:
IOException- may be thrown by subclassses- Since:
- 4.3
-
getContentType
protected org.apache.http.entity.ContentType getContentType(org.apache.http.HttpEntity entity) - Since:
- 4.4
-
responseReceived
public final void responseReceived(org.apache.http.HttpResponse response) throws IOException, org.apache.http.HttpException UseonResponseReceived(HttpResponse)instead.- Specified by:
responseReceivedin interfaceHttpAsyncResponseConsumer<T>- Parameters:
response- HTTP response message.- Throws:
IOException- in case of an I/O errororg.apache.http.HttpException- in case of HTTP protocol violation
-
consumeContent
UseonContentReceived(ContentDecoder, IOControl)instead.- Specified by:
consumeContentin interfaceHttpAsyncResponseConsumer<T>- Parameters:
decoder- content decoder.ioControl- I/O control of the underlying connection.- Throws:
IOException- in case of an I/O error
-
responseCompleted
public final void responseCompleted(org.apache.http.protocol.HttpContext context) UsebuildResult(HttpContext)instead.- Specified by:
responseCompletedin interfaceHttpAsyncResponseConsumer<T>- Parameters:
context- HTTP context
-
cancel
public final boolean cancel()- Specified by:
cancelin interfaceorg.apache.http.concurrent.Cancellable
-
failed
Description copied from interface:HttpAsyncResponseConsumerInvoked to signal that the response processing terminated abnormally.- Specified by:
failedin interfaceHttpAsyncResponseConsumer<T>- Parameters:
ex- exception
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getException
Description copied from interface:HttpAsyncResponseConsumerReturns an exception in case of an abnormal termination. This method returnsnullif the response processing is still ongoing or if it completed successfully.- Specified by:
getExceptionin interfaceHttpAsyncResponseConsumer<T>- See Also:
-
getResult
Description copied from interface:HttpAsyncResponseConsumerReturns a result of the response processing, when available. This method returnsnullif the response processing is still ongoing.- Specified by:
getResultin interfaceHttpAsyncResponseConsumer<T>- See Also:
-
isDone
public boolean isDone()Description copied from interface:HttpAsyncResponseConsumerDetermines whether or not the response processing completed. If the response processing terminated normallyHttpAsyncResponseConsumer.getResult()can be used to obtain the result. If the response processing terminated abnormallyHttpAsyncResponseConsumer.getException()can be used to obtain the cause.- Specified by:
isDonein interfaceHttpAsyncResponseConsumer<T>
-