Class 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 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 encoded Pair 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 encoded Pair 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 the Credentials object to be used for generating authorization signatures.
        Parameters:
        credentials - The Credentials object.
        Returns:
        This ApiClient instance for method chaining.
      • getCredentials

        public Credentials getCredentials()
        Get the Credentials object currently used for generating authorization signatures.
        Returns:
        The Credentials object.
      • setObjectMapper

        public ApiClient setObjectMapper​(com.fasterxml.jackson.databind.ObjectMapper mapper)
        Set a custom ObjectMapper 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 current ObjectMapper.
        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, then HttpClient::send throws an HttpConnectTimeoutException, or HttpClient::sendAsync completes exceptionally with an HttpConnectTimeoutException. 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