Class CompletableResponseListener

java.lang.Object
org.eclipse.jetty.client.BufferingResponseListener
org.eclipse.jetty.client.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

public class CompletableResponseListener extends BufferingResponseListener

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);