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
ConstructorDescriptionCompletableResponseListener
(Request request) CompletableResponseListener
(Request request, int maxLength) -
Method Summary
Modifier and TypeMethodDescriptionvoid
onComplete
(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 aCompletableFuture
that is completed when the request/response completes.send
(Connection connection) Sends the request asynchronously via the givenConnection
and returns aCompletableFuture
that is completed when the request/response completes.send
(Destination destination) Sends the request asynchronously via the givenDestination
and returns aCompletableFuture
that is completed when the request/response completes.Methods inherited from class org.eclipse.jetty.client.BufferingResponseListener
getContent, getContentAsInputStream, getContentAsString, getContentAsString, getContentAsString, getEncoding, getMediaType, onContent, onHeaders
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.client.Response.AsyncContentListener
onContentSource
Methods inherited from interface org.eclipse.jetty.client.Response.ContentListener
onContent
Methods inherited from interface org.eclipse.jetty.client.Response.Listener
onBegin, onFailure, onHeader, onSuccess
-
Constructor Details
-
CompletableResponseListener
-
CompletableResponseListener
-
-
Method Details
-
getRequest
- Returns:
- the
Request
associated with this listener
-
send
Sends the request asynchronously and returns a
CompletableFuture
that is completed when the request/response completes.- Returns:
- a
CompletableFuture
that is completed when the request/response completes - See Also:
-
send
Sends the request asynchronously via the given
Destination
and returns aCompletableFuture
that is completed when the request/response completes.- Parameters:
destination
- the destination to send the request to- Returns:
- a
CompletableFuture
that is completed when the request/response completes - See Also:
-
send
Sends the request asynchronously via the given
Connection
and returns aCompletableFuture
that is completed when the request/response completes.- Parameters:
connection
- the connection to send the request to- Returns:
- a
CompletableFuture
that is completed when the request/response completes - See Also:
-
onComplete
Description copied from interface:Response.CompleteListener
Callback method invoked when the request and the response have been processed, either successfully or not.The
result
parameter 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:
onComplete
in interfaceResponse.CompleteListener
- Specified by:
onComplete
in interfaceResponse.Listener
- Specified by:
onComplete
in classBufferingResponseListener
- Parameters:
result
- the result of the request / response exchange
-