Class HttpProperties


  • public final class HttpProperties
    extends java.lang.Object
    Internal container for HTTP parameters used by SDK components. Includes logic for creating an OkHttp client.

    This is separate from any public HTTP configuration/builder classes that are part of the SDK API. Those are transformed into this when the SDK is constructing components. The public API does not reference any OkHttp classes, but this internal class does.

    • Constructor Summary

      Constructors 
      Constructor Description
      HttpProperties​(long connectTimeoutMillis, java.util.Map<java.lang.String,​java.lang.String> defaultHeaders, HeadersTransformer headersTransformer, java.net.Proxy proxy, okhttp3.Authenticator proxyAuth, javax.net.SocketFactory socketFactory, long socketTimeoutMillis, javax.net.ssl.SSLSocketFactory sslSocketFactory, javax.net.ssl.X509TrustManager trustManager)
      Constructs an instance.
      HttpProperties​(okhttp3.OkHttpClient sharedHttpClient, java.util.Map<java.lang.String,​java.lang.String> defaultHeaders, HeadersTransformer headersTransformer)
      Constructs an instance with a preconfigured shared HTTP client.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyToHttpClientBuilder​(okhttp3.OkHttpClient.Builder builder)
      Applies the configured properties to an OkHttp client builder.
      static HttpProperties defaults()
      Returns a minimal set of properties.
      java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>> getDefaultHeaders()
      Returns an immutable view of the default headers.
      HeadersTransformer getHeadersTransformer()
      Returns the callback for transforming headers, if any.
      okhttp3.OkHttpClient getSharedHttpClient()
      Returns a preconfigured shared HTTP client, if one was defined.
      java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>> getTransformedDefaultHeaders()
      Returns an immutable view of the headers to add to a request.
      static void shutdownHttpClient​(okhttp3.OkHttpClient client)
      Attempts to completely shut down an OkHttp client.
      okhttp3.Headers.Builder toHeadersBuilder()
      Returns an OkHttp Headers builder initialized with the default headers.
      okhttp3.OkHttpClient.Builder toHttpClientBuilder()
      Returns an OkHttp client builder initialized with the configured properties.
      • Methods inherited from class java.lang.Object

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

      • HttpProperties

        public HttpProperties​(long connectTimeoutMillis,
                              java.util.Map<java.lang.String,​java.lang.String> defaultHeaders,
                              HeadersTransformer headersTransformer,
                              java.net.Proxy proxy,
                              okhttp3.Authenticator proxyAuth,
                              javax.net.SocketFactory socketFactory,
                              long socketTimeoutMillis,
                              javax.net.ssl.SSLSocketFactory sslSocketFactory,
                              javax.net.ssl.X509TrustManager trustManager)
        Constructs an instance.
        Parameters:
        connectTimeoutMillis - connection timeout milliseconds
        defaultHeaders - headers to add to all requests
        headersTransformer - optional callback to modify headers
        proxy - optional proxy
        proxyAuth - optional proxy authenticator
        socketFactory - optional socket factory
        socketTimeoutMillis - socket timeout milliseconds
        sslSocketFactory - optional SSL socket factory
        trustManager - optional SSL trust manager
      • HttpProperties

        public HttpProperties​(okhttp3.OkHttpClient sharedHttpClient,
                              java.util.Map<java.lang.String,​java.lang.String> defaultHeaders,
                              HeadersTransformer headersTransformer)
        Constructs an instance with a preconfigured shared HTTP client.
        Parameters:
        sharedHttpClient - an existing HTTP client instance
        defaultHeaders - headers to add to all requests
        headersTransformer - optional callback to modify headers
    • Method Detail

      • defaults

        public static HttpProperties defaults()
        Returns a minimal set of properties.
        Returns:
        a default instance
      • getDefaultHeaders

        public java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>> getDefaultHeaders()
        Returns an immutable view of the default headers. This does not include applying the configured HeadersTransformer, if any.
        Returns:
        the default headers
        See Also:
        toHeadersBuilder()
      • getTransformedDefaultHeaders

        public java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>> getTransformedDefaultHeaders()
        Returns an immutable view of the headers to add to a request. This includes applying the configured HeadersTransformer, if any.
        Returns:
        the default headers
        See Also:
        toHeadersBuilder()
      • getSharedHttpClient

        public okhttp3.OkHttpClient getSharedHttpClient()
        Returns a preconfigured shared HTTP client, if one was defined.

        SDK components that use HttpProperties should check this method first before attempting to build their own client. If it returns a non-null value, they should use that client; in that case, no other properties except the default headers are relevant, and they should not take ownership of the client (that is, do not close the client when the component is closed).

        Returns:
        an HTTP client or null
      • applyToHttpClientBuilder

        public void applyToHttpClientBuilder​(okhttp3.OkHttpClient.Builder builder)
        Applies the configured properties to an OkHttp client builder.

        SDK components that use HttpProperties should check getSharedHttpClient() first before attempting to build their own client. The applyToHttpClientBuilder(okhttp3.OkHttpClient.Builder) method will not provide a correct configuration if a shared client was specified.

        Parameters:
        builder - the client builder
      • toHttpClientBuilder

        public okhttp3.OkHttpClient.Builder toHttpClientBuilder()
        Returns an OkHttp client builder initialized with the configured properties.

        SDK components that use HttpProperties should check getSharedHttpClient() first before attempting to build their own client. The toHttpClientBuilder() method will not provide a correct configuration if a shared client was specified.

        Returns:
        a client builder
      • toHeadersBuilder

        public okhttp3.Headers.Builder toHeadersBuilder()
        Returns an OkHttp Headers builder initialized with the default headers. This includes calling the configured HeadersTransformer, if any.
        Returns:
        a Headers builder
      • shutdownHttpClient

        public static void shutdownHttpClient​(okhttp3.OkHttpClient client)
        Attempts to completely shut down an OkHttp client.
        Parameters:
        client - the client to stop