Class JdkAsyncHttpClientBuilder
java.lang.Object
com.azure.core.http.jdk.httpclient.JdkAsyncHttpClientBuilder
Builder to configure and build an instance of the azure-core
HttpClient
type using the JDK HttpClient APIs,
first introduced as preview in JDK 9, but made generally available from JDK 11 onwards.-
Constructor Summary
ConstructorDescriptionCreates JdkAsyncHttpClientBuilder.JdkAsyncHttpClientBuilder
(java.net.http.HttpClient.Builder httpClientBuilder) Creates JdkAsyncHttpClientBuilder from the builder of an existingHttpClient.Builder
. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build a HttpClient with current configurations.configuration
(Configuration configuration) Sets the configuration store that is used during construction of the HTTP client.connectionTimeout
(Duration connectionTimeout) Sets the connection timeout.Sets the executor to be used for asynchronous and dependent tasks.proxy
(ProxyOptions proxyOptions) Sets the proxy.
-
Constructor Details
-
JdkAsyncHttpClientBuilder
public JdkAsyncHttpClientBuilder()Creates JdkAsyncHttpClientBuilder. -
JdkAsyncHttpClientBuilder
public JdkAsyncHttpClientBuilder(java.net.http.HttpClient.Builder httpClientBuilder) Creates JdkAsyncHttpClientBuilder from the builder of an existingHttpClient.Builder
.- Parameters:
httpClientBuilder
- the HttpClient builder to use- Throws:
NullPointerException
- ifhttpClientBuilder
is null
-
-
Method Details
-
executor
Sets the executor to be used for asynchronous and dependent tasks. This cannot be null.If this method is not invoked prior to building, a default executor is created for each newly built
HttpClient
.- Parameters:
executor
- the executor to be used for asynchronous and dependent tasks- Returns:
- the updated JdkAsyncHttpClientBuilder object
- Throws:
NullPointerException
- ifexecutor
is null
-
connectionTimeout
Sets the connection timeout.Code Samples
HttpClient client = new JdkAsyncHttpClientBuilder() .connectionTimeout(Duration.ofSeconds(250)) // connection timeout of 250 seconds .build();
The default connection timeout is 60 seconds.- Parameters:
connectionTimeout
- the connection timeout- Returns:
- the updated JdkAsyncHttpClientBuilder object
-
proxy
Sets the proxy.Code Samples
final String proxyHost = "<proxy-host>"; // e.g. localhost final int proxyPort = 9999; // Proxy port ProxyOptions proxyOptions = new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); HttpClient client = new JdkAsyncHttpClientBuilder() .proxy(proxyOptions) .build();
- Parameters:
proxyOptions
- The proxy configuration to use.- Returns:
- the updated
JdkAsyncHttpClientBuilder
object
-
configuration
Sets the configuration store that is used during construction of the HTTP client.The default configuration store is a clone of the
global configuration store
, useConfiguration.NONE
to bypass using configuration settings during construction.- Parameters:
configuration
- The configuration store used to- Returns:
- The updated JdkAsyncHttpClientBuilder object.
-
build
Build a HttpClient with current configurations.- Returns:
- a
HttpClient
.
-