Class TableServiceClientBuilder

java.lang.Object
com.azure.data.tables.TableServiceClientBuilder
All Implemented Interfaces:
com.azure.core.client.traits.AzureNamedKeyCredentialTrait<TableServiceClientBuilder>, com.azure.core.client.traits.AzureSasCredentialTrait<TableServiceClientBuilder>, com.azure.core.client.traits.ConfigurationTrait<TableServiceClientBuilder>, com.azure.core.client.traits.ConnectionStringTrait<TableServiceClientBuilder>, com.azure.core.client.traits.EndpointTrait<TableServiceClientBuilder>, com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>, com.azure.core.client.traits.TokenCredentialTrait<TableServiceClientBuilder>

public final class TableServiceClientBuilder extends Object implements com.azure.core.client.traits.TokenCredentialTrait<TableServiceClientBuilder>, com.azure.core.client.traits.AzureNamedKeyCredentialTrait<TableServiceClientBuilder>, com.azure.core.client.traits.ConnectionStringTrait<TableServiceClientBuilder>, com.azure.core.client.traits.AzureSasCredentialTrait<TableServiceClientBuilder>, com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>, com.azure.core.client.traits.ConfigurationTrait<TableServiceClientBuilder>, com.azure.core.client.traits.EndpointTrait<TableServiceClientBuilder>
Provides a fluent builder API to help aid the configuration and instantiation of TableServiceClient and TableServiceAsyncClient.

Overview

This class provides a fluent builder API to help aid the configuration and instantiation of TableServiceClient and TableServiceAsyncClient objects. Call buildClient() or buildAsyncClient(), respectively, to construct an instance of the desired client.

Getting Started

The minimal configuration options required by TableServiceClientBuilder to build a TableServiceClient or TableServiceAsyncClient are an endpoint and a form of authentication, which can be set via: connectionString(String), credential(AzureNamedKeyCredential), credential(TokenCredential), credential(AzureSasCredential), or sasToken(String)

To build a TableServiceClient or TableServiceAsyncClient instance, call buildClient() or buildAsyncClient(), respectively.

The following example shows how to build a TableServiceClient.

 TableServiceClient tableServiceClient = new TableServiceClientBuilder()
     .connectionString("connectionString")
     .buildClient();
 

The following example shows how to build a TableServiceAsyncClient.

 TableServiceAsyncClient tableServiceClient = new TableServiceClientBuilder()
     .connectionString("connectionString")
     .buildAsyncClient();
 

Authentication via Connection String

To use a connection string to authorize the client, call the builder's connectionString(String) method with your connection string. When authenticating via a connection string, providing an endpoint is not required.

 TableServiceClient tableServiceClient = new TableServiceClientBuilder()
     .connectionString("connectionstring")
     .buildClient();
 

Authentication via Shared Key

To use shared key authentication, create an instance of AzureNamedKeyCredential and pass it to the builder's credential(AzureNamedKeyCredential) method. Pass the account URL to the builder's endpoint(String) method.

 TableServiceClient tableServiceClient = new TableServiceClientBuilder()
     .endpoint("endpoint")
     .credential(new AzureNamedKeyCredential("name", "key"))
     .buildClient();
 

Authentication via Shared Access Signature (SAS)

When authorizing a client utilizing a Shared Access Signature (SAS), you have the option of using AzureSasCredential or the SAS token directly. To use an AzureSasCredential, pass it to the builder's credential(AzureSasCredential) method. When authenticating with a SAS token, pass it to the builder's sasToken(String) method. Pass the account URL to the builder's endpoint(String) method.

Using AzureSasCredential:

 TableServiceClient tableServiceClient = new TableServiceClientBuilder()
     .endpoint("endpoint")
     .credential(new AzureSasCredential("sasToken"))
     .buildClient();
 

Using a SAS token:

 TableServiceClient tableServiceClient = new TableServiceClientBuilder()
     .endpoint("endpoint")
     .sasToken("sasToken")
     .buildClient();
 

Authentication via Token Credential

To use token credential authentication, create an instance of a credential class that implements TokenCredential and pass it to the builder's credential(TokenCredential) method. Pass the account URL to the builder's endpoint(String) method.

 TableServiceClient tableServiceClient = new TableServiceClientBuilder()
     .endpoint("endpoint")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildClient();
 
See Also:
  • Constructor Details

  • Method Details

    • buildClient

      public TableServiceClient buildClient()
      Creates a TableServiceClient based on options set in the builder.
      Returns:
      A TableServiceClient created from the configurations in this builder.
      Throws:
      NullPointerException - If endpoint is null.
      IllegalArgumentException - If endpoint is malformed or empty.
      IllegalStateException - If no form of authentication or endpoint have been specified or if multiple forms of authentication are provided, with the exception of sasToken + connectionString. Also thrown if endpoint and/or sasToken are set alongside a connectionString and the endpoint and/or SAS token in the latter are different than the former, respectively.
    • buildAsyncClient

      public TableServiceAsyncClient buildAsyncClient()
      Creates a TableServiceAsyncClient based on options set in the builder.
      Returns:
      A TableServiceAsyncClient created from the configurations in this builder.
      Throws:
      NullPointerException - If endpoint is null.
      IllegalArgumentException - If endpoint is malformed or empty.
      IllegalStateException - If no form of authentication or endpoint have been specified or if multiple forms of authentication are provided, with the exception of sasToken + connectionString. Also thrown if endpoint and/or sasToken are set alongside a connectionString and the endpoint and/or SAS token in the latter are different than the former, respectively.
    • connectionString

      public TableServiceClientBuilder connectionString(String connectionString)
      Sets the connection string to connect to the service.
      Specified by:
      connectionString in interface com.azure.core.client.traits.ConnectionStringTrait<TableServiceClientBuilder>
      Parameters:
      connectionString - Connection string of the storage or CosmosDB table API account.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      NullPointerException - If connectionString is null.
      IllegalArgumentException - If connectionString isn't a valid connection string.
    • endpoint

      public TableServiceClientBuilder endpoint(String endpoint)
      Sets the service endpoint.
      Specified by:
      endpoint in interface com.azure.core.client.traits.EndpointTrait<TableServiceClientBuilder>
      Parameters:
      endpoint - The URL of the storage or CosmosDB table API account endpoint.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      IllegalArgumentException - If endpoint isn't a valid URL.
    • pipeline

      public TableServiceClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
      Sets the HttpPipeline to use for the service client.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      The endpoint is not ignored when pipeline is set.

      Specified by:
      pipeline in interface com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>
      Parameters:
      pipeline - HttpPipeline to use for sending service requests and receiving responses.
      Returns:
      The updated TableServiceClientBuilder.
    • configuration

      public TableServiceClientBuilder configuration(com.azure.core.util.Configuration configuration)
      Sets the configuration object used to retrieve environment configuration values during building of the client.

      The default configuration store is a clone of the global configuration store, use Configuration.NONE to bypass using configuration settings during construction.

      Specified by:
      configuration in interface com.azure.core.client.traits.ConfigurationTrait<TableServiceClientBuilder>
      Parameters:
      configuration - Configuration store used to retrieve environment configuration.
      Returns:
      The updated TableServiceClientBuilder.
    • sasToken

      public TableServiceClientBuilder sasToken(String sasToken)
      Sets the SAS token used to authorize requests sent to the service. Setting this is mutually exclusive with credential(AzureNamedKeyCredential), credential(AzureSasCredential) or credential(TokenCredential).
      Parameters:
      sasToken - The SAS token to use for authenticating requests.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      NullPointerException - If sasToken is null.
      IllegalArgumentException - If sasToken is empty.
    • credential

      public TableServiceClientBuilder credential(com.azure.core.credential.AzureSasCredential credential)
      Sets the AzureSasCredential used to authorize requests sent to the service. Setting this is mutually exclusive with credential(AzureNamedKeyCredential), credential(TokenCredential) or sasToken(String).
      Specified by:
      credential in interface com.azure.core.client.traits.AzureSasCredentialTrait<TableServiceClientBuilder>
      Parameters:
      credential - AzureSasCredential used to authorize requests sent to the service.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      NullPointerException - If credential is null.
    • credential

      public TableServiceClientBuilder credential(com.azure.core.credential.AzureNamedKeyCredential credential)
      Sets the AzureNamedKeyCredential used to authorize requests sent to the service. Setting this is mutually exclusive with using credential(AzureSasCredential), credential(TokenCredential) or sasToken(String).
      Specified by:
      credential in interface com.azure.core.client.traits.AzureNamedKeyCredentialTrait<TableServiceClientBuilder>
      Parameters:
      credential - AzureNamedKeyCredential used to authorize requests sent to the service.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      NullPointerException - If credential is null.
    • credential

      public TableServiceClientBuilder credential(com.azure.core.credential.TokenCredential credential)
      Sets the TokenCredential used to authorize requests sent to the service. Refer to the Azure SDK for Java identity and authentication documentation for more details on proper usage of the TokenCredential type. Setting this is mutually exclusive with using credential(AzureNamedKeyCredential), credential(AzureSasCredential) or sasToken(String).
      Specified by:
      credential in interface com.azure.core.client.traits.TokenCredentialTrait<TableServiceClientBuilder>
      Parameters:
      credential - TokenCredential used to authorize requests sent to the service.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      NullPointerException - If credential is null.
    • httpClient

      public TableServiceClientBuilder httpClient(com.azure.core.http.HttpClient httpClient)
      Sets the HttpClient to use for sending and receiving requests to and from the service.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      httpClient in interface com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>
      Parameters:
      httpClient - The HttpClient to use for requests.
      Returns:
      The updated TableServiceClientBuilder.
    • httpLogOptions

      public TableServiceClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
      Sets the logging configuration to use when sending and receiving requests to and from the service. If a logLevel is not provided, default value of HttpLogDetailLevel.NONE is set.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      httpLogOptions in interface com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>
      Parameters:
      logOptions - The logging configuration to use when sending and receiving requests to and from the service.
      Returns:
      The updated TableServiceClientBuilder.
    • addPolicy

      public TableServiceClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy pipelinePolicy)
      Adds a pipeline policy to apply on each request sent.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      addPolicy in interface com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>
      Parameters:
      pipelinePolicy - A pipeline policy.
      Returns:
      The updated TableServiceClientBuilder.
      Throws:
      NullPointerException - If pipelinePolicy is null.
    • serviceVersion

      public TableServiceClientBuilder serviceVersion(TableServiceVersion serviceVersion)
      Sets the service version that is used when making API requests.

      If a service version is not provided, the service version that will be used will be the latest known service version based on the version of the client library being used. If no service version is specified, updating to a newer version of the client library will have the result of potentially moving to a newer service version.

      Targeting a specific service version may also mean that the service will return an error for newer APIs.

      Parameters:
      serviceVersion - The TableServiceVersion of the service to be used when making requests.
      Returns:
      The updated TableServiceClientBuilder.
    • retryPolicy

      public TableServiceClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
      Sets the request RetryPolicy for all the requests made through the client. The default RetryPolicy will be used in the pipeline, if not provided. Setting this is mutually exclusive with using retryOptions(RetryOptions).
      Parameters:
      retryPolicy - RetryPolicy.
      Returns:
      The updated TableServiceClientBuilder.
    • retryOptions

      public TableServiceClientBuilder retryOptions(com.azure.core.http.policy.RetryOptions retryOptions)
      Sets the RetryOptions for all the requests made through the client.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Setting this is mutually exclusive with using retryPolicy(RetryPolicy).

      Specified by:
      retryOptions in interface com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>
      Parameters:
      retryOptions - The RetryOptions to use for all the requests made through the client.
      Returns:
      The updated TableServiceClientBuilder object.
    • clientOptions

      public TableServiceClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
      Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is recommended that this method be called with an instance of the HttpClientOptions class (a subclass of the ClientOptions base class). The HttpClientOptions subclass provides more configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait interface.

      Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

      Specified by:
      clientOptions in interface com.azure.core.client.traits.HttpTrait<TableServiceClientBuilder>
      Parameters:
      clientOptions - A configured instance of HttpClientOptions.
      Returns:
      The updated TableServiceClientBuilder.
      See Also:
      • HttpClientOptions
    • enableTenantDiscovery

      public TableServiceClientBuilder enableTenantDiscovery()
      Enable tenant discovery when authenticating with the Table Service. This functionality is disabled by default and only available for Storage endpoints using service version 2020_12_06.

      Enable this if there is a chance for your application and the Storage account it communicates with to reside in different tenants. If this is enabled, clients created using this builder will make an unauthorized initial service request that will be met with a 401 response containing an authentication challenge, which will be subsequently used to retrieve an access token to authorize all further requests with.

      Returns:
      The updated TableServiceClientBuilder.