Package com.microsoft.rest
Class RestClient.Builder
- java.lang.Object
-
- com.microsoft.rest.RestClient.Builder
-
- Enclosing class:
- RestClient
public static class RestClient.Builder extends Object
The builder class for building a REST client.
-
-
Constructor Summary
Constructors Constructor Description Builder()Creates an instance of the builder with a base URL to the service.Builder(okhttp3.OkHttpClient.Builder httpClientBuilder, retrofit2.Retrofit.Builder retrofitBuilder)Creates an instance of the builder with a base URL and 2 custom builders.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RestClientbuild()Build a RestClient with all the current configurations.RestClient.BuilderuseHttpClientThreadPool(boolean useHttpClientThreadPool)Sets whether to use the thread pool in OkHttp client or RxJava schedulers.RestClient.BuilderwithBaseUrl(Environment environment, Environment.Endpoint endpoint)Sets the base URL with the default from the Environment.RestClient.BuilderwithBaseUrl(String baseUrl)Sets the dynamic base URL.RestClient.BuilderwithCallbackExecutor(Executor executor)Sets the executor for async callbacks to run on.RestClient.BuilderwithConnectionPool(okhttp3.ConnectionPool connectionPool)Sets the connection pool for the Http client.RestClient.BuilderwithConnectionTimeout(long timeout, TimeUnit unit)Set the connection timeout on the HTTP client.RestClient.BuilderwithCredentials(ServiceClientCredentials credentials)Sets the credentials.RestClient.BuilderwithDispatcher(okhttp3.Dispatcher dispatcher)Sets the dispatcher used in OkHttp client.RestClient.BuilderwithInterceptor(okhttp3.Interceptor interceptor)Add an interceptor the Http client pipeline.RestClient.BuilderwithLogLevel(LogLevel logLevel)Sets the HTTP log level.RestClient.BuilderwithMaxIdleConnections(int maxIdleConnections)Deprecated.usewithConnectionPool(ConnectionPool)insteadRestClient.BuilderwithNetworkInterceptor(okhttp3.Interceptor networkInterceptor)Add an interceptor the network layer of Http client pipeline.RestClient.BuilderwithProxy(Proxy proxy)Sets the proxy for the HTTP client.RestClient.BuilderwithProxyAuthenticator(okhttp3.Authenticator proxyAuthenticator)Sets the proxy authenticator for the HTTP client.RestClient.BuilderwithReadTimeout(long timeout, TimeUnit unit)Set the read timeout on the HTTP client.RestClient.BuilderwithResponseBuilderFactory(ResponseBuilder.Factory responseBuilderFactory)Sets the response builder factory.RestClient.BuilderwithRetryStrategy(RetryStrategy strategy)Adds a retry strategy to the client.RestClient.BuilderwithSerializerAdapter(SerializerAdapter<?> serializerAdapter)Sets the serialization adapter.RestClient.BuilderwithUserAgent(String userAgent)Sets the user agent header.
-
-
-
Constructor Detail
-
Builder
public Builder()
Creates an instance of the builder with a base URL to the service.
-
Builder
public Builder(okhttp3.OkHttpClient.Builder httpClientBuilder, retrofit2.Retrofit.Builder retrofitBuilder)Creates an instance of the builder with a base URL and 2 custom builders.- Parameters:
httpClientBuilder- the builder to build anOkHttpClient.retrofitBuilder- the builder to build aRetrofit.
-
-
Method Detail
-
withBaseUrl
public RestClient.Builder withBaseUrl(String baseUrl)
Sets the dynamic base URL.- Parameters:
baseUrl- the base URL to use.- Returns:
- the builder itself for chaining.
-
withBaseUrl
public RestClient.Builder withBaseUrl(Environment environment, Environment.Endpoint endpoint)
Sets the base URL with the default from the Environment.- Parameters:
environment- the environment to useendpoint- the environment endpoint the application is accessing- Returns:
- the builder itself for chaining
-
withSerializerAdapter
public RestClient.Builder withSerializerAdapter(SerializerAdapter<?> serializerAdapter)
Sets the serialization adapter.- Parameters:
serializerAdapter- the adapter to a serializer- Returns:
- the builder itself for chaining
-
withResponseBuilderFactory
public RestClient.Builder withResponseBuilderFactory(ResponseBuilder.Factory responseBuilderFactory)
Sets the response builder factory.- Parameters:
responseBuilderFactory- the response builder factory- Returns:
- the builder itself for chaining
-
withCredentials
public RestClient.Builder withCredentials(ServiceClientCredentials credentials)
Sets the credentials.- Parameters:
credentials- the credentials object.- Returns:
- the builder itself for chaining.
-
withUserAgent
public RestClient.Builder withUserAgent(String userAgent)
Sets the user agent header.- Parameters:
userAgent- the user agent header.- Returns:
- the builder itself for chaining.
-
withLogLevel
public RestClient.Builder withLogLevel(LogLevel logLevel)
Sets the HTTP log level.- Parameters:
logLevel- theLogLevelenum.- Returns:
- the builder itself for chaining.
-
withInterceptor
public RestClient.Builder withInterceptor(okhttp3.Interceptor interceptor)
Add an interceptor the Http client pipeline.- Parameters:
interceptor- the interceptor to add.- Returns:
- the builder itself for chaining.
-
withNetworkInterceptor
public RestClient.Builder withNetworkInterceptor(okhttp3.Interceptor networkInterceptor)
Add an interceptor the network layer of Http client pipeline.- Parameters:
networkInterceptor- the interceptor to add.- Returns:
- the builder itself for chaining.
-
withReadTimeout
public RestClient.Builder withReadTimeout(long timeout, TimeUnit unit)
Set the read timeout on the HTTP client. Default is 10 seconds.- Parameters:
timeout- the timeout numeric valueunit- the time unit for the numeric value- Returns:
- the builder itself for chaining
-
withConnectionTimeout
public RestClient.Builder withConnectionTimeout(long timeout, TimeUnit unit)
Set the connection timeout on the HTTP client. Default is 10 seconds.- Parameters:
timeout- the timeout numeric valueunit- the time unit for the numeric value- Returns:
- the builder itself for chaining
-
withMaxIdleConnections
@Deprecated public RestClient.Builder withMaxIdleConnections(int maxIdleConnections)
Deprecated.usewithConnectionPool(ConnectionPool)insteadSet the maximum idle connections for the HTTP client. Default is 5.- Parameters:
maxIdleConnections- the maximum idle connections- Returns:
- the builder itself for chaining
-
withConnectionPool
public RestClient.Builder withConnectionPool(okhttp3.ConnectionPool connectionPool)
Sets the connection pool for the Http client.- Parameters:
connectionPool- the OkHttp 3 connection pool to use- Returns:
- the builder itself for chaining
-
useHttpClientThreadPool
public RestClient.Builder useHttpClientThreadPool(boolean useHttpClientThreadPool)
Sets whether to use the thread pool in OkHttp client or RxJava schedulers. If set to true, the thread pool in OkHttp client will be used. Default is false.- Parameters:
useHttpClientThreadPool- whether to use the thread pool in Okhttp client. Default is false.- Returns:
- the builder itself for chaining
-
withDispatcher
public RestClient.Builder withDispatcher(okhttp3.Dispatcher dispatcher)
Sets the dispatcher used in OkHttp client. This is also where to set the thread pool for executing HTTP requests.- Parameters:
dispatcher- the dispatcher to use- Returns:
- the builder itself for chaining
-
withCallbackExecutor
public RestClient.Builder withCallbackExecutor(Executor executor)
Sets the executor for async callbacks to run on.- Parameters:
executor- the executor to execute the callbacks.- Returns:
- the builder itself for chaining
-
withProxy
public RestClient.Builder withProxy(Proxy proxy)
Sets the proxy for the HTTP client.- Parameters:
proxy- the proxy to use- Returns:
- the builder itself for chaining
-
withProxyAuthenticator
public RestClient.Builder withProxyAuthenticator(okhttp3.Authenticator proxyAuthenticator)
Sets the proxy authenticator for the HTTP client.- Parameters:
proxyAuthenticator- the proxy authenticator to use- Returns:
- the builder itself for chaining
-
withRetryStrategy
public RestClient.Builder withRetryStrategy(RetryStrategy strategy)
Adds a retry strategy to the client.- Parameters:
strategy- the retry strategy to add- Returns:
- the builder itself for chaining
-
build
public RestClient build()
Build a RestClient with all the current configurations.- Returns:
- a
RestClient.
-
-