Class AbstractResponseListener
java.lang.Object
org.eclipse.jetty.client.AbstractResponseListener
- All Implemented Interfaces:
EventListener, Response.AsyncContentListener, Response.BeginListener, Response.CompleteListener, Response.ContentListener, Response.ContentSourceListener, Response.FailureListener, Response.HeaderListener, Response.HeadersListener, Response.Listener, Response.ResponseListener, Response.SuccessListener
- Direct Known Subclasses:
BufferingResponseListener, RetainingResponseListener
Instances of this class are not reusable, so one must be allocated for each request.
The content may be retrieved from Response.Listener.onSuccess(Response) or Response.Listener.onComplete(Result)
via one of the getContent*() or takeContent*() methods.
IMPORTANT: The content MUST be consumed by calling one of the getContent*() or
takeContent*() methods otherwise the backing buffers may be leaked. If either of
takeContentAsInputStream() or takeContentAsContentSource() is called, the content
MUST be read until the end (or closed/failed appropriately) otherwise the backing buffers of the unread
content may also be leaked.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractResponseListener(RetainableByteBuffer.Mutable accumulator) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Return the content asInputStream.getContentAsString(String encoding) getContentAsString(Charset charset) longvoidonContent(Response response, ByteBuffer content) Callback method invoked when the response content has been received, parsed and there is demand.voidonContent(Response response, Content.Chunk chunk, Runnable demander) Callback method invoked when the response content has been received, parsed and there is demand.voidCallback method invoked when the response has failed in the process of being receivedvoidCallback method invoked when all the response headers have been received and parsed.Take the content and return it asContent.Source.Take the content and return it asInputStream.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Response.AsyncContentListener
onContentSourceMethods inherited from interface Response.Listener
onBegin, onComplete, onHeader, onSuccess
-
Constructor Details
-
AbstractResponseListener
-
-
Method Details
-
getMaxLength
public long getMaxLength() -
getEncoding
-
getMediaType
-
onHeaders
Description copied from interface:Response.HeadersListenerCallback method invoked when all the response headers have been received and parsed.- Specified by:
onHeadersin interfaceResponse.HeadersListener- Specified by:
onHeadersin interfaceResponse.Listener- Parameters:
response- the response containing the response line data and the headers
-
onContent
Description copied from interface:Response.AsyncContentListenerCallback method invoked when the response content has been received, parsed and there is demand. Thechunkmust be consumed, copied, or retained before returning from this method as it is then automatically released. Thedemandermust be run before this method may be invoked again.- Specified by:
onContentin interfaceResponse.AsyncContentListener- Specified by:
onContentin interfaceResponse.ContentListener- Parameters:
response- the response containing the response line data and the headerschunk- the chunk receiveddemander- the runnable to be run to demand the next chunk- Throws:
Exception- an uncaught exception will abort the response, release the chunk and fail the content source from which the chunk was read from
-
onContent
Description copied from interface:Response.ContentListenerCallback method invoked when the response content has been received, parsed and there is demand. This method may be invoked multiple times, and thecontentbuffer must be consumed (or copied) before returning from this method. This method is also always invoked when content arrives as demand is automatically registered on return.- Specified by:
onContentin interfaceResponse.ContentListener- Specified by:
onContentin interfaceResponse.Listener- Parameters:
response- the response containing the response line data and the headerscontent- the content bytes received
-
onFailure
Description copied from interface:Response.FailureListenerCallback method invoked when the response has failed in the process of being received- Specified by:
onFailurein interfaceResponse.FailureListener- Specified by:
onFailurein interfaceResponse.Listener- Parameters:
response- the response containing data up to the point the failure happenedfailure- the failure happened
-
getContent
public byte[] getContent()- Returns:
- the content as a byte array.
- See Also:
-
getContentAsString
- Returns:
- the content as a string, using the "Content-Type" header to detect the encoding or defaulting to UTF-8 if the encoding could not be detected.
- See Also:
-
getContentAsString
-
getContentAsString
-
getContentAsInputStream
Return the content asInputStream. A copy of the content is kept in memory to allow the followinggetContent*()andtakeContent*()calls to read the content again.- Returns:
- the content as
InputStream
-
takeContentAsInputStream
Take the content and return it asInputStream. FollowinggetContent*()andtakeContent*()calls will see an empty content.- Returns:
- the content as
InputStream
-
takeContentAsContentSource
Take the content and return it asContent.Source. FollowinggetContent*()andtakeContent*()calls will see an empty content.- Returns:
- the content as
Content.Source
-