Class DocumentAnalysisClientBuilder
- java.lang.Object
-
- com.azure.ai.formrecognizer.DocumentAnalysisClientBuilder
-
public final class DocumentAnalysisClientBuilder extends Object
This class provides a fluent builder API to help instantiation ofDocumentAnalysisClients
andDocumentAnalysisAsyncClients
, callbuildClient()
buildClient} andbuildAsyncClient
respectively to construct an instance of the desired client.The client needs the service endpoint of the Azure Document Analysis to access the resource service.
credential(AzureKeyCredential)
orcredential(TokenCredential)
gives the builder access credential.Instantiating an asynchronous Document Analysis Client
DocumentAnalysisAsyncClient documentAnalysisAsyncClient = new DocumentAnalysisClientBuilder() .credential(new AzureKeyCredential("{key}")) .endpoint("{endpoint}") .buildAsyncClient();
Instantiating a synchronous Document Analysis Client
DocumentAnalysisClient documentAnalysisClient = new DocumentAnalysisClientBuilder() .credential(new AzureKeyCredential("{key}")) .endpoint("{endpoint}") .buildClient();
Another way to construct the client is using a
HttpPipeline
. The pipeline gives the client an authenticated way to communicate with the service. Set the pipeline withthis
and set the service endpoint withthis
. Using a pipeline requires additional setup but allows for finer control on how theDocumentAnalysisClient
andDocumentAnalysisAsyncClient
is built.HttpPipeline pipeline = new HttpPipelineBuilder() .policies(/* add policies */) .build(); DocumentAnalysisClient documentAnalysisClient = new DocumentAnalysisClientBuilder() .credential(new AzureKeyCredential("{key}")) .endpoint("{endpoint}") .pipeline(pipeline) .buildClient();
-
-
Constructor Summary
Constructors Constructor Description DocumentAnalysisClientBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DocumentAnalysisClientBuilder
addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed after required policies.DocumentAnalysisAsyncClient
buildAsyncClient()
Creates aDocumentAnalysisAsyncClient
based on options set in the builder.DocumentAnalysisClient
buildClient()
Creates aDocumentAnalysisClient
based on options set in the builder.DocumentAnalysisClientBuilder
clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets the client options such as application ID and custom headers to set on a request.DocumentAnalysisClientBuilder
configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client.DocumentAnalysisClientBuilder
credential(com.azure.core.credential.AzureKeyCredential azureKeyCredential)
Sets theAzureKeyCredential
to use when authenticating HTTP requests for this DocumentAnalysisClientBuilder.DocumentAnalysisClientBuilder
credential(com.azure.core.credential.TokenCredential tokenCredential)
Sets theTokenCredential
used to authenticate HTTP requests.DocumentAnalysisClientBuilder
endpoint(String endpoint)
Sets the service endpoint for the Azure Document Analysis instance.static com.azure.core.http.policy.HttpLogOptions
getDefaultLogOptions()
Gets the default Azure Document Analysis client headers and query parameters that are logged by default if HTTP logging is enabled.DocumentAnalysisClientBuilder
httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.DocumentAnalysisClientBuilder
httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.DocumentAnalysisClientBuilder
pipeline(com.azure.core.http.HttpPipeline httpPipeline)
Sets the HTTP pipeline to use for the service client.DocumentAnalysisClientBuilder
retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicy()
that is used when each request is sent.DocumentAnalysisClientBuilder
serviceVersion(DocumentAnalysisServiceVersion version)
Sets theDocumentAnalysisServiceVersion
that is used when making API requests.
-
-
-
Method Detail
-
buildClient
public DocumentAnalysisClient buildClient()
Creates aDocumentAnalysisClient
based on options set in the builder. Every timebuildClient()
is called a new instance ofDocumentAnalysisClient
is created.If
pipeline
is set, then thepipeline
andendpoint
are used to create theclient
. All other builder settings are ignored.- Returns:
- A DocumentAnalysisClient with the options set from the builder.
- Throws:
NullPointerException
- ifendpoint
orcredential(AzureKeyCredential)
has not been set.IllegalArgumentException
- ifendpoint
cannot be parsed into a valid URL.
-
buildAsyncClient
public DocumentAnalysisAsyncClient buildAsyncClient()
Creates aDocumentAnalysisAsyncClient
based on options set in the builder. Every timebuildAsyncClient()
is called a new instance ofDocumentAnalysisAsyncClient
is created.If
pipeline
is set, then thepipeline
andendpoint
are used to create theclient
. All other builder settings are ignored.- Returns:
- A DocumentAnalysisAsyncClient with the options set from the builder.
- Throws:
NullPointerException
- ifendpoint
orcredential(AzureKeyCredential)
has not been set.IllegalArgumentException
- ifendpoint
cannot be parsed into a valid URL.
-
endpoint
public DocumentAnalysisClientBuilder endpoint(String endpoint)
Sets the service endpoint for the Azure Document Analysis instance.- Parameters:
endpoint
- The URL of the Azure Document Analysis instance service requests to and receive responses from.- Returns:
- The updated DocumentAnalysisClientBuilder object.
- Throws:
NullPointerException
- ifendpoint
is nullIllegalArgumentException
- ifendpoint
cannot be parsed into a valid URL.
-
credential
public DocumentAnalysisClientBuilder credential(com.azure.core.credential.AzureKeyCredential azureKeyCredential)
Sets theAzureKeyCredential
to use when authenticating HTTP requests for this DocumentAnalysisClientBuilder.- Parameters:
azureKeyCredential
-AzureKeyCredential
API key credential- Returns:
- The updated DocumentAnalysisClientBuilder object.
- Throws:
NullPointerException
- IfazureKeyCredential
is null.
-
credential
public DocumentAnalysisClientBuilder credential(com.azure.core.credential.TokenCredential tokenCredential)
Sets theTokenCredential
used to authenticate HTTP requests.- Parameters:
tokenCredential
-TokenCredential
used to authenticate HTTP requests.- Returns:
- The updated
DocumentAnalysisClientBuilder
object. - Throws:
NullPointerException
- IftokenCredential
is null.
-
httpLogOptions
public DocumentAnalysisClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.If
logOptions
isn't provided, the default options will useHttpLogDetailLevel.NONE
which will prevent logging.- Parameters:
logOptions
- The logging configuration to use when sending and receiving HTTP requests/responses.- Returns:
- The updated DocumentAnalysisClientBuilder object.
-
getDefaultLogOptions
public static com.azure.core.http.policy.HttpLogOptions getDefaultLogOptions()
Gets the default Azure Document Analysis client headers and query parameters that are logged by default if HTTP logging is enabled.- Returns:
- The default
HttpLogOptions
allow list.
-
clientOptions
public DocumentAnalysisClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets the client options such as application ID and custom headers to set on a request.- Parameters:
clientOptions
- The client options.- Returns:
- The updated DocumentAnalysisClientBuilder object.
-
addPolicy
public DocumentAnalysisClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed after required policies.- Parameters:
policy
- The retry policy for service requests.- Returns:
- The updated DocumentAnalysisClientBuilder object.
- Throws:
NullPointerException
- Ifpolicy
is null.
-
httpClient
public DocumentAnalysisClientBuilder httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.- Parameters:
client
- The HTTP client to use for requests.- Returns:
- The updated DocumentAnalysisClientBuilder object.
-
pipeline
public DocumentAnalysisClientBuilder pipeline(com.azure.core.http.HttpPipeline httpPipeline)
Sets the HTTP pipeline to use for the service client.If
pipeline
is set, all other settings are ignored, aside fromendpoint
to buildDocumentAnalysisAsyncClient
orDocumentAnalysisClient
.- Parameters:
httpPipeline
- The HTTP pipeline to use for sending service requests and receiving responses.- Returns:
- The updated DocumentAnalysisClientBuilder object.
-
configuration
public DocumentAnalysisClientBuilder configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service 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 DocumentAnalysisClientBuilder object.
-
retryPolicy
public DocumentAnalysisClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicy()
that is used when each request is sent.The default retry policy will be used if not provided
buildAsyncClient()
to buildDocumentAnalysisAsyncClient
orDocumentAnalysisClient
.- Parameters:
retryPolicy
- user's retry policy applied to each request.- Returns:
- The updated DocumentAnalysisClientBuilder object.
-
serviceVersion
public DocumentAnalysisClientBuilder serviceVersion(DocumentAnalysisServiceVersion version)
Sets theDocumentAnalysisServiceVersion
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 the client library will have the result of potentially moving to a newer service version.
- Parameters:
version
-DocumentAnalysisServiceVersion
of the service to be used when making requests.- Returns:
- The updated DocumentAnalysisClientBuilder object.
-
-