Class JdkAsyncHttpClientBuilder

java.lang.Object
com.azure.core.http.jdk.httpclient.JdkAsyncHttpClientBuilder

public class JdkAsyncHttpClientBuilder extends Object
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 Details

    • JdkAsyncHttpClientBuilder

      public JdkAsyncHttpClientBuilder()
      Creates JdkAsyncHttpClientBuilder.
    • JdkAsyncHttpClientBuilder

      public JdkAsyncHttpClientBuilder(java.net.http.HttpClient.Builder httpClientBuilder)
      Creates JdkAsyncHttpClientBuilder from the builder of an existing HttpClient.Builder.
      Parameters:
      httpClientBuilder - the HttpClient builder to use
      Throws:
      NullPointerException - if httpClientBuilder is null
  • Method Details

    • executor

      public JdkAsyncHttpClientBuilder executor(Executor 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 - if executor is null
    • connectionTimeout

      public JdkAsyncHttpClientBuilder connectionTimeout(Duration 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

      public JdkAsyncHttpClientBuilder proxy(ProxyOptions proxyOptions)
      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

      public JdkAsyncHttpClientBuilder configuration(Configuration 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, use Configuration.NONE to bypass using configuration settings during construction.

      Parameters:
      configuration - The configuration store used to
      Returns:
      The updated JdkAsyncHttpClientBuilder object.
    • build

      public HttpClient build()
      Build a HttpClient with current configurations.
      Returns:
      a HttpClient.