public interface HttpClient
Modifier and Type | Method and Description |
---|---|
HttpResponse |
send(HttpRequest request,
int responseTimeout,
boolean followRedirects,
HttpAuthentication authentication)
Sends a HttpRequest blocking the current thread until a response is available or the request times out.
|
CompletableFuture<HttpResponse> |
sendAsync(HttpRequest request,
int responseTimeout,
boolean followRedirects,
HttpAuthentication authentication)
Sends a HttpRequest without blocking the current thread.
|
void |
start()
Fully configures the client, leaving it ready to use.
|
void |
stop()
Disables the client.
|
void start()
void stop()
HttpResponse send(HttpRequest request, int responseTimeout, boolean followRedirects, HttpAuthentication authentication) throws IOException, TimeoutException
request
- the HttpRequest
to sendresponseTimeout
- the time (in milliseconds) to wait for a responsefollowRedirects
- whether or not to follow redirect responsesauthentication
- the optional HttpAuthentication
to useHttpResponse
IOException
- if an error occurs while executingTimeoutException
- if responseTimeout
is exceededCompletableFuture<HttpResponse> sendAsync(HttpRequest request, int responseTimeout, boolean followRedirects, HttpAuthentication authentication)
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.request
- the HttpRequest
to sendresponseTimeout
- the time (in milliseconds) to wait for a responsefollowRedirects
- whether or not to follow redirect responsesauthentication
- the optional HttpAuthentication
to useCompletableFuture
that will complete once the HttpResponse
is availableCopyright © 2018. All rights reserved.