Package unit.java.sdk

Class ApiClient


  • @Generated(value="org.openapitools.codegen.languages.JavaClientCodegen",
               comments="Generator version: 7.9.0")
    public class ApiClient
    extends java.lang.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​(java.net.http.HttpClient.Builder builder, com.fasterxml.jackson.databind.ObjectMapper mapper, java.lang.String baseUri)
      Create an instance of ApiClient.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.net.http.HttpClient.Builder createDefaultHttpClientBuilder()  
      protected com.fasterxml.jackson.databind.ObjectMapper createDefaultObjectMapper()  
      java.util.function.Consumer<java.net.http.HttpResponse<java.lang.String>> getAsyncResponseInterceptor()
      Get the custom async response interceptor.
      java.lang.String getBaseUri()
      Get the base URI to resolve the endpoint paths against.
      java.time.Duration getConnectTimeout()
      Get connection timeout (in milliseconds).
      protected java.lang.String getDefaultBaseUri()  
      java.net.http.HttpClient getHttpClient()
      Get an HttpClient based on the current HttpClient.Builder.
      com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      Get a copy of the current ObjectMapper.
      java.time.Duration getReadTimeout()
      Get the read timeout that was set.
      java.util.function.Consumer<java.net.http.HttpRequest.Builder> getRequestInterceptor()
      Get the custom interceptor.
      java.util.function.Consumer<java.net.http.HttpResponse<java.io.InputStream>> getResponseInterceptor()
      Get the custom response interceptor.
      static java.util.List<Pair> parameterToPairs​(java.lang.String name, java.lang.Object value)
      Convert a URL query name/value parameter to a list of encoded Pair objects.
      static java.util.List<Pair> parameterToPairs​(java.lang.String collectionFormat, java.lang.String name, java.util.Collection<?> values)
      Convert a URL query name/collection parameter to a list of encoded Pair objects.
      ApiClient setAsyncResponseInterceptor​(java.util.function.Consumer<java.net.http.HttpResponse<java.lang.String>> interceptor)
      Set a custom async response interceptor.
      ApiClient setBasePath​(java.lang.String basePath)
      Set a custom base path for the target service, for example '/v2'.
      ApiClient setConnectTimeout​(java.time.Duration connectTimeout)
      Sets the connect timeout (in milliseconds) for the http client.
      ApiClient setHost​(java.lang.String host)
      Set a custom host name for the target service.
      ApiClient setHttpClientBuilder​(java.net.http.HttpClient.Builder builder)
      Set a custom HttpClient.Builder object to use when creating the HttpClient that is used by the API client.
      ApiClient setObjectMapper​(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Set a custom ObjectMapper to serialize and deserialize the request and response bodies.
      ApiClient setPort​(int port)
      Set a custom port number for the target service.
      ApiClient setReadTimeout​(java.time.Duration readTimeout)
      Set the read timeout for the http client.
      ApiClient setRequestInterceptor​(java.util.function.Consumer<java.net.http.HttpRequest.Builder> interceptor)
      Set a custom request interceptor.
      ApiClient setResponseInterceptor​(java.util.function.Consumer<java.net.http.HttpResponse<java.io.InputStream>> interceptor)
      Set a custom response interceptor.
      ApiClient setScheme​(java.lang.String scheme)
      Set a custom scheme for the target service, for example 'https'.
      void updateBaseUri​(java.lang.String baseUri)  
      static java.lang.String urlEncode​(java.lang.String s)
      URL encode a string in the UTF-8 encoding.
      static java.lang.String valueToString​(java.lang.Object value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ApiClient

        public ApiClient()
        Create an instance of ApiClient.
      • ApiClient

        public ApiClient​(java.net.http.HttpClient.Builder builder,
                         com.fasterxml.jackson.databind.ObjectMapper mapper,
                         java.lang.String baseUri)
        Create an instance of ApiClient.
        Parameters:
        builder - Http client builder.
        mapper - Object mapper.
        baseUri - Base URI
    • Method Detail

      • valueToString

        public static java.lang.String valueToString​(java.lang.Object value)
      • urlEncode

        public static java.lang.String urlEncode​(java.lang.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 java.util.List<Pair> parameterToPairs​(java.lang.String name,
                                                            java.lang.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 java.util.List<Pair> parameterToPairs​(java.lang.String collectionFormat,
                                                            java.lang.String name,
                                                            java.util.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 java.lang.String getDefaultBaseUri()
      • createDefaultHttpClientBuilder

        protected java.net.http.HttpClient.Builder createDefaultHttpClientBuilder()
      • updateBaseUri

        public void updateBaseUri​(java.lang.String baseUri)
      • setHttpClientBuilder

        public ApiClient setHttpClientBuilder​(java.net.http.HttpClient.Builder builder)
        Set a custom HttpClient.Builder object to use when creating the HttpClient that is used by the API client.
        Parameters:
        builder - Custom client builder.
        Returns:
        This object.
      • getHttpClient

        public java.net.http.HttpClient getHttpClient()
        Get an HttpClient based on the current HttpClient.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 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​(java.lang.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​(java.lang.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 java.lang.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​(java.lang.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​(java.util.function.Consumer<java.net.http.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 java.util.function.Consumer<java.net.http.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​(java.util.function.Consumer<java.net.http.HttpResponse<java.io.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 java.util.function.Consumer<java.net.http.HttpResponse<java.io.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​(java.util.function.Consumer<java.net.http.HttpResponse<java.lang.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 java.util.function.Consumer<java.net.http.HttpResponse<java.lang.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​(java.time.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 java.time.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​(java.time.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 java.time.Duration getConnectTimeout()
        Get connection timeout (in milliseconds).
        Returns:
        Timeout in milliseconds