RestClient.Builder Class

  • java.lang.Object
    • com.microsoft.bot.restclient.RestClient.Builder

public static class RestClient.Builder

The builder class for building a REST client.

Constructor Summary

Constructor Description
Builder()

Creates an instance of the builder with a base URL to the service.

Builder(OkHttpClient.Builder httpClientBuilder, Retrofit.Builder retrofitBuilder)

Creates an instance of the builder with a base URL and 2 custom builders.

Method Summary

Modifier and Type Method and Description
RestClient build()

Build a RestClient with all the current configurations.

Builder useHttpClientThreadPool(boolean useHttpClientThreadPool)

Sets whether to use the thread pool in OkHttp client or RxJava schedulers.

Builder withBaseUrl(Environment environment, Environment.Endpoint endpoint)

Sets the base URL with the default from the Environment.

Builder withBaseUrl(String baseUrl)

Sets the dynamic base URL.

Builder withCallbackExecutor(Executor executor)

Sets the executor for async callbacks to run on.

Builder withConnectionPool(ConnectionPool connectionPool)

Sets the connection pool for the Http client.

Builder withConnectionTimeout(long timeout, TimeUnit unit)

Set the connection timeout on the HTTP client.

Builder withCredentials(ServiceClientCredentials credentials)

Sets the credentials.

Builder withDispatcher(Dispatcher dispatcher)

Sets the dispatcher used in OkHttp client.

Builder withInterceptor(Interceptor interceptor)

Add an interceptor the Http client pipeline.

Builder withLogLevel(LogLevel logLevel)

Sets the HTTP log level.

Builder withMaxIdleConnections(int maxIdleConnections)

Deprecated

Set the maximum idle connections for the HTTP client.

Builder withNetworkInterceptor(Interceptor networkInterceptor)

Add an interceptor the network layer of Http client pipeline.

Builder withProxy(Proxy proxy)

Sets the proxy for the HTTP client.

Builder withProxyAuthenticator(Authenticator proxyAuthenticator)

Sets the proxy authenticator for the HTTP client.

Builder withReadTimeout(long timeout, TimeUnit unit)

Set the read timeout on the HTTP client.

Builder withResponseBuilderFactory(ResponseBuilder.Factory responseBuilderFactory)

Sets the response builder factory.

Builder withRetryStrategy(RetryStrategy strategy)

Adds a retry strategy to the client.

Builder withSerializerAdapter(SerializerAdapter<?> serializerAdapter)

Sets the serialization adapter.

Builder withUserAgent(String userAgent)

Sets the user agent header.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

Builder

public Builder()

Creates an instance of the builder with a base URL to the service.

Builder

public Builder(OkHttpClient.Builder httpClientBuilder, Retrofit.Builder retrofitBuilder)

Creates an instance of the builder with a base URL and 2 custom builders.

Parameters:

httpClientBuilder - the builder to build an OkHttpClient.
retrofitBuilder - the builder to build a Retrofit.

Method Details

build

public RestClient build()

Build a RestClient with all the current configurations.

Returns:

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

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 use
endpoint - the environment endpoint the application is accessing

Returns:

the builder itself for chaining

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.

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

withConnectionPool

public RestClient.Builder withConnectionPool(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

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 value
unit - the time unit for the numeric value

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.

withDispatcher

public RestClient.Builder withDispatcher(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

withInterceptor

public RestClient.Builder withInterceptor(Interceptor interceptor)

Add an interceptor the Http client pipeline.

Parameters:

interceptor - the interceptor to add.

Returns:

the builder itself for chaining.

withLogLevel

public RestClient.Builder withLogLevel(LogLevel logLevel)

Sets the HTTP log level.

Parameters:

logLevel - the LogLevel enum.

Returns:

the builder itself for chaining.

withMaxIdleConnections


public RestClient.Builder withMaxIdleConnections(int maxIdleConnections)

Deprecated

Set the maximum idle connections for the HTTP client. Default is 5.

Parameters:

maxIdleConnections - the maximum idle connections

Returns:

the builder itself for chaining

withNetworkInterceptor

public RestClient.Builder withNetworkInterceptor(Interceptor networkInterceptor)

Add an interceptor the network layer of Http client pipeline.

Parameters:

networkInterceptor - the interceptor to add.

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(Authenticator proxyAuthenticator)

Sets the proxy authenticator for the HTTP client.

Parameters:

proxyAuthenticator - the proxy authenticator to use

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 value
unit - the time unit for the numeric value

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

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

withSerializerAdapter

public RestClient.Builder withSerializerAdapter(SerializerAdapter serializerAdapter)

Sets the serialization adapter.

Parameters:

serializerAdapter - the adapter to a serializer

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.

Applies to