Class ApiClient
- java.lang.Object
-
- com.exoscale.sdk.client.ApiClient
-
@Generated(value="org.openapitools.codegen.languages.JavaClientCodegen", comments="Generator version: 7.4.0") public class ApiClient extends Object
Configuration and utility class for API clients.This class can be constructed and modified, then used to instantiate the various API classes. The API classes use the settings in this class to configure themselves, but otherwise do not store a link to this class.
This class is mutable and not synchronized, so it is not thread-safe. The API classes generated from this are immutable and thread-safe.
The setter methods of this class return the current object to facilitate a fluent style of configuration.
-
-
Constructor Summary
Constructors Constructor Description ApiClient()
Create an instance of ApiClient.ApiClient(Credentials credentials)
Create an instance of ApiClient.ApiClient(HttpClient.Builder builder, com.fasterxml.jackson.databind.ObjectMapper mapper, String baseUri)
Create an instance of ApiClient.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected HttpClient.Builder
createDefaultHttpClientBuilder()
protected com.fasterxml.jackson.databind.ObjectMapper
createDefaultObjectMapper()
Consumer<HttpResponse<String>>
getAsyncResponseInterceptor()
Get the custom async response interceptor.String
getBaseUri()
Get the base URI to resolve the endpoint paths against.Duration
getConnectTimeout()
Get connection timeout (in milliseconds).Credentials
getCredentials()
Get theCredentials
object currently used for generating authorization signatures.protected String
getDefaultBaseUri()
HttpClient
getHttpClient()
Get anHttpClient
based on the currentHttpClient.Builder
.com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Get a copy of the currentObjectMapper
.Duration
getReadTimeout()
Get the read timeout that was set.Consumer<HttpRequest.Builder>
getRequestInterceptor()
Get the custom interceptor.Consumer<HttpResponse<InputStream>>
getResponseInterceptor()
Get the custom response interceptor.static List<Pair>
parameterToPairs(String name, Object value)
Convert a URL query name/value parameter to a list of encodedPair
objects.static List<Pair>
parameterToPairs(String collectionFormat, String name, Collection<?> values)
Convert a URL query name/collection parameter to a list of encodedPair
objects.ApiClient
setAsyncResponseInterceptor(Consumer<HttpResponse<String>> interceptor)
Set a custom async response interceptor.ApiClient
setBasePath(String basePath)
Set a custom base path for the target service, for example '/v2'.ApiClient
setConnectTimeout(Duration connectTimeout)
Sets the connect timeout (in milliseconds) for the http client.ApiClient
setCredentials(Credentials credentials)
Set theCredentials
object to be used for generating authorization signatures.ApiClient
setHost(String host)
Set a custom host name for the target service.ApiClient
setHttpClientBuilder(HttpClient.Builder builder)
Set a customHttpClient.Builder
object to use when creating theHttpClient
that is used by the API client.ApiClient
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Set a customObjectMapper
to serialize and deserialize the request and response bodies.ApiClient
setPort(int port)
Set a custom port number for the target service.ApiClient
setReadTimeout(Duration readTimeout)
Set the read timeout for the http client.ApiClient
setRequestInterceptor(Consumer<HttpRequest.Builder> interceptor)
Set a custom request interceptor.ApiClient
setResponseInterceptor(Consumer<HttpResponse<InputStream>> interceptor)
Set a custom response interceptor.ApiClient
setScheme(String scheme)
Set a custom scheme for the target service, for example 'https'.void
updateBaseUri(String baseUri)
static String
urlEncode(String s)
URL encode a string in the UTF-8 encoding.
-
-
-
Constructor Detail
-
ApiClient
public ApiClient()
Create an instance of ApiClient.
-
ApiClient
public ApiClient(Credentials credentials)
Create an instance of ApiClient.- Parameters:
credentials
- Credentials.mapper
- Object mapper.
-
ApiClient
public ApiClient(HttpClient.Builder builder, com.fasterxml.jackson.databind.ObjectMapper mapper, String baseUri)
Create an instance of ApiClient.- Parameters:
builder
- Http client builder.mapper
- Object mapper.baseUri
- Base URI
-
-
Method Detail
-
urlEncode
public static String urlEncode(String s)
URL encode a string in the UTF-8 encoding.- Parameters:
s
- String to encode.- Returns:
- URL-encoded representation of the input string.
-
parameterToPairs
public static List<Pair> parameterToPairs(String name, Object value)
Convert a URL query name/value parameter to a list of encodedPair
objects.The value can be null, in which case an empty list is returned.
- Parameters:
name
- The query name parameter.value
- The query value, which may not be a collection but may be null.- Returns:
- A singleton list of the
Pair
objects representing the input parameters, which is encoded for use in a URL. If the value is null, an empty list is returned.
-
parameterToPairs
public static List<Pair> parameterToPairs(String collectionFormat, String name, Collection<?> values)
Convert a URL query name/collection parameter to a list of encodedPair
objects.- Parameters:
collectionFormat
- The swagger collectionFormat string (csv, tsv, etc).name
- The query name parameter.values
- A collection of values for the given query name, which may be null.- Returns:
- A list of
Pair
objects representing the input parameters, which is encoded for use in a URL. If the values collection is null, an empty list is returned.
-
createDefaultObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper createDefaultObjectMapper()
-
getDefaultBaseUri
protected String getDefaultBaseUri()
-
createDefaultHttpClientBuilder
protected HttpClient.Builder createDefaultHttpClientBuilder()
-
updateBaseUri
public void updateBaseUri(String baseUri)
-
setCredentials
public ApiClient setCredentials(Credentials credentials)
Set theCredentials
object to be used for generating authorization signatures.- Parameters:
credentials
- TheCredentials
object.- Returns:
- This
ApiClient
instance for method chaining.
-
getCredentials
public Credentials getCredentials()
Get theCredentials
object currently used for generating authorization signatures.- Returns:
- The
Credentials
object.
-
setHttpClientBuilder
public ApiClient setHttpClientBuilder(HttpClient.Builder builder)
Set a customHttpClient.Builder
object to use when creating theHttpClient
that is used by the API client.- Parameters:
builder
- Custom client builder.- Returns:
- This object.
-
getHttpClient
public HttpClient getHttpClient()
Get anHttpClient
based on the currentHttpClient.Builder
.The returned object is immutable and thread-safe.
- Returns:
- The HTTP client.
-
setObjectMapper
public ApiClient setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)
Set a customObjectMapper
to serialize and deserialize the request and response bodies.- Parameters:
mapper
- Custom object mapper.- Returns:
- This object.
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Get a copy of the currentObjectMapper
.- Returns:
- A copy of the current object mapper.
-
setHost
public ApiClient setHost(String host)
Set a custom host name for the target service.- Parameters:
host
- The host name of the target service.- Returns:
- This object.
-
setPort
public ApiClient setPort(int port)
Set a custom port number for the target service.- Parameters:
port
- The port of the target service. Set this to -1 to reset the value to the default for the scheme.- Returns:
- This object.
-
setBasePath
public ApiClient setBasePath(String basePath)
Set a custom base path for the target service, for example '/v2'.- Parameters:
basePath
- The base path against which the rest of the path is resolved.- Returns:
- This object.
-
getBaseUri
public String getBaseUri()
Get the base URI to resolve the endpoint paths against.- Returns:
- The complete base URI that the rest of the API parameters are resolved against.
-
setScheme
public ApiClient setScheme(String scheme)
Set a custom scheme for the target service, for example 'https'.- Parameters:
scheme
- The scheme of the target service- Returns:
- This object.
-
setRequestInterceptor
public ApiClient setRequestInterceptor(Consumer<HttpRequest.Builder> interceptor)
Set a custom request interceptor.A request interceptor is a mechanism for altering each request before it is sent. After the request has been fully configured but not yet built, the request builder is passed into this function for further modification, after which it is sent out.
This is useful for altering the requests in a custom manner, such as adding headers. It could also be used for logging and monitoring.
- Parameters:
interceptor
- A function invoked before creating each request. A value of null resets the interceptor to a no-op.- Returns:
- This object.
-
getRequestInterceptor
public Consumer<HttpRequest.Builder> getRequestInterceptor()
Get the custom interceptor.- Returns:
- The custom interceptor that was set, or null if there isn't any.
-
setResponseInterceptor
public ApiClient setResponseInterceptor(Consumer<HttpResponse<InputStream>> interceptor)
Set a custom response interceptor.This is useful for logging, monitoring or extraction of header variables
- Parameters:
interceptor
- A function invoked before creating each request. A value of null resets the interceptor to a no-op.- Returns:
- This object.
-
getResponseInterceptor
public Consumer<HttpResponse<InputStream>> getResponseInterceptor()
Get the custom response interceptor.- Returns:
- The custom interceptor that was set, or null if there isn't any.
-
setAsyncResponseInterceptor
public ApiClient setAsyncResponseInterceptor(Consumer<HttpResponse<String>> interceptor)
Set a custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.This is useful for logging, monitoring or extraction of header variables
- Parameters:
interceptor
- A function invoked before creating each request. A value of null resets the interceptor to a no-op.- Returns:
- This object.
-
getAsyncResponseInterceptor
public Consumer<HttpResponse<String>> getAsyncResponseInterceptor()
Get the custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.- Returns:
- The custom interceptor that was set, or null if there isn't any.
-
setReadTimeout
public ApiClient setReadTimeout(Duration readTimeout)
Set the read timeout for the http client.This is the value used by default for each request, though it can be overridden on a per-request basis with a request interceptor.
- Parameters:
readTimeout
- The read timeout used by default by the http client. Setting this value to null resets the timeout to an effectively infinite value.- Returns:
- This object.
-
getReadTimeout
public Duration getReadTimeout()
Get the read timeout that was set.- Returns:
- The read timeout, or null if no timeout was set. Null represents an infinite wait time.
-
setConnectTimeout
public ApiClient setConnectTimeout(Duration connectTimeout)
Sets the connect timeout (in milliseconds) for the http client.In the case where a new connection needs to be established, if the connection cannot be established within the given
duration
, thenHttpClient::send
throws anHttpConnectTimeoutException
, orHttpClient::sendAsync
completes exceptionally with anHttpConnectTimeoutException
. If a new connection does not need to be established, for example if a connection can be reused from a previous request, then this timeout duration has no effect.- Parameters:
connectTimeout
- connection timeout in milliseconds- Returns:
- This object.
-
getConnectTimeout
public Duration getConnectTimeout()
Get connection timeout (in milliseconds).- Returns:
- Timeout in milliseconds
-
-