public final class ManagedLifecycleHttpClient extends Object implements HttpClient
HttpClient so that invocations to HttpClient.start() and HttpClient.stop() have no effect.
This is useful (and recommended) for cases in which a given component owns an HttpClient but needs to expose said
client to other consumers. Since the lifecycle of the client should only be handled by the owner, it is good practice to use
this decorator whenever the client is exposed, to guarantee that faulty consumers don't interfere with its lifecycle.
| Constructor and Description |
|---|
ManagedLifecycleHttpClient(HttpClient httpClient)
Creates a new instance
|
| Modifier and Type | Method and Description |
|---|---|
HttpResponse |
send(HttpRequest request,
HttpRequestOptions options)
Sends a HttpRequest blocking the current thread until a response is available or the request times out.
|
CompletableFuture<HttpResponse> |
sendAsync(HttpRequest request,
HttpRequestOptions options)
Sends a HttpRequest without blocking the current thread.
|
void |
start()
Does nothing
|
void |
stop()
Does nothing
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitopenWebSocket, openWebSocket, send, send, sendAsync, sendAsyncpublic ManagedLifecycleHttpClient(HttpClient httpClient)
httpClient - the decorated clientpublic void stop()
stop in interface HttpClientpublic void start()
start in interface HttpClientpublic CompletableFuture<HttpResponse> sendAsync(HttpRequest request, HttpRequestOptions options)
CompletableFuture will be completed. Be aware that the response body processing will be deferred so that the response can
be processed even when a large body is still being received. If the full response is needed right away then the provided
HttpResponse must be read in a different thread so that it does not block the HttpClient threads handling the
response. It's therefore recommended to use CompletableFuture.get() or any of the async methods available, such as
CompletableFuture.whenCompleteAsync(BiConsumer, Executor), to handle the response is those scenarios since they guarantee
executing on a different thread.sendAsync in interface HttpClientrequest - the HttpRequest to sendoptions - the HttpRequestOptions to useCompletableFuture that will complete once the HttpResponse is availablepublic HttpResponse send(HttpRequest request, HttpRequestOptions options) throws IOException, TimeoutException
send in interface HttpClientrequest - the HttpRequest to sendoptions - the HttpRequestOptions to useHttpResponseIOException - if an error occurs while executingTimeoutException - if responseTimeout is exceededCopyright © 2003–2020 MuleSoft, Inc.. All rights reserved.