Class JdkHttpClientBuilder
java.lang.Object
com.azure.core.http.jdk.httpclient.JdkHttpClientBuilder
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
ConstructorsConstructorDescriptionCreates JdkHttpClientBuilder.JdkHttpClientBuilder(java.net.http.HttpClient.Builder httpClientBuilder) Creates JdkHttpClientBuilder 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
-
JdkHttpClientBuilder
public JdkHttpClientBuilder()Creates JdkHttpClientBuilder. -
JdkHttpClientBuilder
public JdkHttpClientBuilder(java.net.http.HttpClient.Builder httpClientBuilder) Creates JdkHttpClientBuilder from the builder of an existingHttpClient.Builder.- Parameters:
httpClientBuilder- the HttpClient builder to use- Throws:
NullPointerException- ifhttpClientBuilderis 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 JdkHttpClientBuilder object
- Throws:
NullPointerException- ifexecutoris null
-
connectionTimeout
Sets the connection timeout.Code Samples
HttpClient client = new JdkHttpClientBuilder() .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 JdkHttpClientBuilder 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 JdkHttpClientBuilder() .proxy(proxyOptions) .build();- Parameters:
proxyOptions- The proxy configuration to use.- Returns:
- the updated JdkHttpClientBuilder 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.NONEto bypass using configuration settings during construction.- Parameters:
configuration- The configuration store used to- Returns:
- The updated JdkHttpClientBuilder object.
-
build
Build a HttpClient with current configurations.- Returns:
- a
HttpClient.
-