Class CompletableResponseListener
- 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
A BufferingResponseListener that sends a Request
and returns a CompletableFuture that is completed when
onComplete(Result) is called.
Typical usage:
var request = client.newRequest(...)...;
CompletableFuture<ContentResponse> completable = new CompletableResponseListener(request).send();
// Attach actions that run when the request/response is complete.
completable.thenApply(response -> ...)
.whenComplete((response, failure) -> ...);
// Possibly even block waiting for the response.
ContentResponse response = completable.get(5, TimeUnit.SECONDS);
-
Constructor Summary
ConstructorsConstructorDescriptionCompletableResponseListener(Request request) CompletableResponseListener(Request request, int maxLength) -
Method Summary
Modifier and TypeMethodDescriptionvoidonComplete(Result result) Callback method invoked when the request and the response have been processed, either successfully or not.send()Sends the request asynchronously and returns aCompletableFuturethat is completed when the request/response completes.send(Connection connection) Sends the request asynchronously via the givenConnectionand returns aCompletableFuturethat is completed when the request/response completes.send(Destination destination) Sends the request asynchronously via the givenDestinationand returns aCompletableFuturethat is completed when the request/response completes.Methods inherited from class BufferingResponseListener
getContent, getContentAsInputStream, getContentAsString, getContentAsString, getContentAsString, getEncoding, getMediaType, onContent, onHeadersMethods 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.ContentListener
onContentMethods inherited from interface Response.Listener
onBegin, onFailure, onHeader, onSuccess
-
Constructor Details
-
CompletableResponseListener
-
CompletableResponseListener
-
-
Method Details
-
getRequest
-
send
Sends the request asynchronously and returns a
CompletableFuturethat is completed when the request/response completes.- Returns:
- a
CompletableFuturethat is completed when the request/response completes - See Also:
-
send
Sends the request asynchronously via the given
Destinationand returns aCompletableFuturethat is completed when the request/response completes.- Parameters:
destination- the destination to send the request to- Returns:
- a
CompletableFuturethat is completed when the request/response completes - See Also:
-
send
Sends the request asynchronously via the given
Connectionand returns aCompletableFuturethat is completed when the request/response completes.- Parameters:
connection- the connection to send the request to- Returns:
- a
CompletableFuturethat is completed when the request/response completes - See Also:
-
onComplete
Description copied from interface:Response.CompleteListenerCallback method invoked when the request and the response have been processed, either successfully or not.The
resultparameter contains the request, the response, and eventual failures.Requests may complete after response, for example in case of big uploads that are discarded or read asynchronously by the server. This method is always invoked after
Response.SuccessListener.onSuccess(Response)orResponse.FailureListener.onFailure(Response, Throwable), and only when request indicates that it is completed.- Specified by:
onCompletein interfaceResponse.CompleteListener- Specified by:
onCompletein interfaceResponse.Listener- Specified by:
onCompletein classBufferingResponseListener- Parameters:
result- the result of the request / response exchange
-