Class HttpUtil


  • public class HttpUtil
    extends Object
    HttpUtil class
    • Field Detail

      • JDBC_MAX_CONNECTIONS_PER_ROUTE_PROPERTY

        public static final String JDBC_MAX_CONNECTIONS_PER_ROUTE_PROPERTY
        See Also:
        Constant Field Values
      • httpClient

        public static Map<HttpClientSettingsKey,​org.apache.http.impl.client.CloseableHttpClient> httpClient
        The unique httpClient shared by all connections. This will benefit long-lived clients. Key = proxy host + proxy port + nonProxyHosts, Value = Map of [OCSPMode, HttpClient]
    • Constructor Detail

      • HttpUtil

        public HttpUtil()
    • Method Detail

      • getDownloadedConditionTimeoutInSeconds

        public static long getDownloadedConditionTimeoutInSeconds()
      • closeExpiredAndIdleConnections

        public static void closeExpiredAndIdleConnections()
      • setSessionlessProxyForAzure

        public static void setSessionlessProxyForAzure​(Properties proxyProperties,
                                                       com.microsoft.azure.storage.OperationContext opContext)
                                                throws SnowflakeSQLException
        A static function to set Azure proxy params for sessionless connections using the proxy params from the StageInfo
        Parameters:
        proxyProperties - proxy properties
        opContext - the configuration needed by Azure to set the proxy
        Throws:
        SnowflakeSQLException - when invalid proxy properties encountered
      • setProxyForAzure

        public static void setProxyForAzure​(HttpClientSettingsKey key,
                                            com.microsoft.azure.storage.OperationContext opContext)
        A static function to set Azure proxy params when there is a valid session
        Parameters:
        key - key to HttpClient map containing OCSP and proxy info
        opContext - the configuration needed by Azure to set the proxy
      • buildHttpClient

        public static org.apache.http.impl.client.CloseableHttpClient buildHttpClient​(@Nullable
                                                                                      HttpClientSettingsKey key,
                                                                                      File ocspCacheFile,
                                                                                      boolean downloadUnCompressed)
        Build an Http client using our set of default.
        Parameters:
        key - Key to HttpClient hashmap containing OCSP mode and proxy information, could be null
        ocspCacheFile - OCSP response cache file. If null, the default OCSP response file will be used.
        downloadUnCompressed - Whether the HTTP client should be built requesting no decompression
        Returns:
        HttpClient object
      • buildHttpClient

        public static org.apache.http.impl.client.CloseableHttpClient buildHttpClient​(@Nullable
                                                                                      HttpClientSettingsKey key,
                                                                                      File ocspCacheFile,
                                                                                      boolean downloadUnCompressed,
                                                                                      List<HttpHeadersCustomizer> httpHeadersCustomizers)
        Build an Http client using our set of default.
        Parameters:
        key - Key to HttpClient hashmap containing OCSP mode and proxy information, could be null
        ocspCacheFile - OCSP response cache file. If null, the default OCSP response file will be used.
        downloadUnCompressed - Whether the HTTP client should be built requesting no decompression
        httpHeadersCustomizers - List of HTTP headers customizers
        Returns:
        HttpClient object
      • getHttpClient

        public static org.apache.http.impl.client.CloseableHttpClient getHttpClient​(HttpClientSettingsKey ocspAndProxyKey)
        Gets HttpClient with insecureMode false
        Parameters:
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        Returns:
        HttpClient object shared across all connections
      • getHttpClientWithoutDecompression

        public static org.apache.http.impl.client.CloseableHttpClient getHttpClientWithoutDecompression​(HttpClientSettingsKey ocspAndProxyKey)
        Gets HttpClient with insecureMode false and disabling decompression
        Parameters:
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        Returns:
        HttpClient object shared across all connections
      • getHttpClient

        public static org.apache.http.impl.client.CloseableHttpClient getHttpClient​(HttpClientSettingsKey ocspAndProxyKey,
                                                                                    List<HttpHeadersCustomizer> httpHeadersCustomizers)
        Gets HttpClient with insecureMode false
        Parameters:
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        httpHeadersCustomizers - List of HTTP headers customizers
        Returns:
        HttpClient object shared across all connections
      • getHttpClientWithoutDecompression

        public static org.apache.http.impl.client.CloseableHttpClient getHttpClientWithoutDecompression​(HttpClientSettingsKey ocspAndProxyKey,
                                                                                                        List<HttpHeadersCustomizer> httpHeadersCustomizers)
        Gets HttpClient with insecureMode false and disabling decompression
        Parameters:
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        httpHeadersCustomizers - List of HTTP headers customizers
        Returns:
        HttpClient object shared across all connections
      • initHttpClientWithoutDecompression

        public static org.apache.http.impl.client.CloseableHttpClient initHttpClientWithoutDecompression​(HttpClientSettingsKey key,
                                                                                                         File ocspCacheFile)
        Accessor for the HTTP client singleton.
        Parameters:
        key - contains information needed to build specific HttpClient
        ocspCacheFile - OCSP response cache file name. if null, the default file will be used.
        Returns:
        HttpClient object shared across all connections
      • initHttpClient

        public static org.apache.http.impl.client.CloseableHttpClient initHttpClient​(HttpClientSettingsKey key,
                                                                                     File ocspCacheFile)
        Accessor for the HTTP client singleton.
        Parameters:
        key - contains information needed to build specific HttpClient
        ocspCacheFile - OCSP response cache file name. if null, the default file will be used.
        Returns:
        HttpClient object shared across all connections
      • initHttpClientWithoutDecompression

        public static org.apache.http.impl.client.CloseableHttpClient initHttpClientWithoutDecompression​(HttpClientSettingsKey key,
                                                                                                         File ocspCacheFile,
                                                                                                         List<HttpHeadersCustomizer> httpHeadersCustomizers)
        Accessor for the HTTP client singleton.
        Parameters:
        key - contains information needed to build specific HttpClient
        ocspCacheFile - OCSP response cache file name. if null, the default file will be used.
        httpHeadersCustomizers - List of HTTP headers customizers
        Returns:
        HttpClient object shared across all connections
      • initHttpClient

        public static org.apache.http.impl.client.CloseableHttpClient initHttpClient​(HttpClientSettingsKey key,
                                                                                     File ocspCacheFile,
                                                                                     List<HttpHeadersCustomizer> httpHeadersCustomizers)
        Accessor for the HTTP client singleton.
        Parameters:
        key - contains information needed to build specific HttpClient
        ocspCacheFile - OCSP response cache file name. if null, the default file will be used.
        httpHeadersCustomizers - List of HTTP headers customizers
        Returns:
        HttpClient object shared across all connections
      • getDefaultRequestConfigWithSocketTimeout

        public static org.apache.http.client.config.RequestConfig getDefaultRequestConfigWithSocketTimeout​(int soTimeoutMs,
                                                                                                           boolean withoutCookies)
        Return a request configuration inheriting from the default request configuration of the shared HttpClient with a different socket timeout.
        Parameters:
        soTimeoutMs - - custom socket timeout in milli-seconds
        withoutCookies - - whether this request should ignore cookies or not
        Returns:
        RequestConfig object
      • getDefaultRequestConfigWithSocketAndConnectTimeout

        public static org.apache.http.client.config.RequestConfig getDefaultRequestConfigWithSocketAndConnectTimeout​(int requestSocketAndConnectTimeout,
                                                                                                                     boolean withoutCookies)
        Return a request configuration inheriting from the default request configuration of the shared HttpClient with a different socket and connect timeout.
        Parameters:
        requestSocketAndConnectTimeout - - custom socket and connect timeout in milli-seconds
        withoutCookies - - whether this request should ignore cookies or not
        Returns:
        RequestConfig object
      • getRequestConfigWithoutCookies

        public static org.apache.http.client.config.RequestConfig getRequestConfigWithoutCookies()
        Return a request configuration inheriting from the default request configuration of the shared HttpClient with the cookie spec set to ignore.
        Returns:
        RequestConfig object
      • setRequestConfig

        public static void setRequestConfig​(org.apache.http.client.config.RequestConfig requestConfig)
      • setSocksProxyDisabled

        public static void setSocksProxyDisabled​(boolean socksProxyDisabled)
        Enables/disables use of the SOCKS proxy when creating sockets
        Parameters:
        socksProxyDisabled - new value
      • isSocksProxyDisabled

        public static boolean isSocksProxyDisabled()
        Returns whether the SOCKS proxy is disabled for this JVM
        Returns:
        whether the SOCKS proxy is disabled
      • executeGeneralRequest

        @Deprecated
        public static String executeGeneralRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                                   int retryTimeout,
                                                   int authTimeout,
                                                   int socketTimeout,
                                                   int retryCount,
                                                   HttpClientSettingsKey ocspAndProxyAndGzipKey)
                                            throws SnowflakeSQLException,
                                                   IOException
        Deprecated.
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator specific timeout
        socketTimeout - socket timeout (in ms)
        retryCount - max retry count for the request - if it is set to 0, it will be ignored and only retryTimeout will determine when to end the retries
        ocspAndProxyAndGzipKey - OCSP mode and proxy settings for httpclient
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeGeneralRequest

        @SnowflakeJdbcInternalApi
        public static String executeGeneralRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                                   int retryTimeout,
                                                   int authTimeout,
                                                   int socketTimeout,
                                                   int retryCount,
                                                   HttpClientSettingsKey ocspAndProxyAndGzipKey,
                                                   SFBaseSession sfSession)
                                            throws SnowflakeSQLException,
                                                   IOException
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator specific timeout
        socketTimeout - socket timeout (in ms)
        retryCount - max retry count for the request - if it is set to 0, it will be ignored and only retryTimeout will determine when to end the retries
        ocspAndProxyAndGzipKey - OCSP mode and proxy settings for httpclient
        sfSession - the session associated with the request
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeGeneralRequest

        @SnowflakeJdbcInternalApi
        public static String executeGeneralRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                                   int retryTimeout,
                                                   int authTimeout,
                                                   int socketTimeout,
                                                   int retryCount,
                                                   HttpClientSettingsKey ocspAndProxyAndGzipKey,
                                                   RetryContextManager retryContextManager,
                                                   SFBaseSession sfSession)
                                            throws SnowflakeSQLException,
                                                   IOException
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator specific timeout
        socketTimeout - socket timeout (in ms)
        retryCount - max retry count for the request - if it is set to 0, it will be ignored and only retryTimeout will determine when to end the retries
        ocspAndProxyAndGzipKey - OCSP mode and proxy settings for httpclient
        retryContextManager - RetryContext used to customize retry handling functionality
        sfSession - the session associated with the request
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeGeneralRequest

        @Deprecated
        public static String executeGeneralRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                                   int retryTimeout,
                                                   int authTimeout,
                                                   int socketTimeout,
                                                   int retryCount,
                                                   org.apache.http.impl.client.CloseableHttpClient httpClient)
                                            throws SnowflakeSQLException,
                                                   IOException
        Deprecated.
        Executes an HTTP request for Snowflake
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator specific timeout
        socketTimeout - socket timeout (in ms)
        retryCount - max retry count for the request - if it is set to 0, it will be ignored and only retryTimeout will determine when to end the retries
        httpClient - client object used to communicate with other machine
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeGeneralRequest

        @SnowflakeJdbcInternalApi
        public static String executeGeneralRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                                   int retryTimeout,
                                                   int authTimeout,
                                                   int socketTimeout,
                                                   int retryCount,
                                                   org.apache.http.impl.client.CloseableHttpClient httpClient,
                                                   SFBaseSession sfSession)
                                            throws SnowflakeSQLException,
                                                   IOException
        Executes an HTTP request for Snowflake
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator specific timeout
        socketTimeout - socket timeout (in ms)
        retryCount - max retry count for the request - if it is set to 0, it will be ignored and only retryTimeout will determine when to end the retries
        httpClient - client object used to communicate with other machine
        sfSession - the session associated with the request
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeRequest

        @Deprecated
        public static String executeRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                            int retryTimeout,
                                            int authTimeout,
                                            int socketTimeout,
                                            int maxRetries,
                                            int injectSocketTimeout,
                                            AtomicBoolean canceling,
                                            boolean includeRetryParameters,
                                            boolean retryOnHTTP403,
                                            HttpClientSettingsKey ocspAndProxyKey,
                                            ExecTimeTelemetryData execTimeData)
                                     throws SnowflakeSQLException,
                                            IOException
        Deprecated.
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator timeout
        socketTimeout - socket timeout (in ms)
        maxRetries - retry count for the request
        injectSocketTimeout - injecting socket timeout
        canceling - canceling?
        includeRetryParameters - whether to include retry parameters in retried requests
        retryOnHTTP403 - whether to retry on HTTP 403 or not
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        execTimeData - query execution time telemetry data object
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeRequest

        @SnowflakeJdbcInternalApi
        public static String executeRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                            int retryTimeout,
                                            int authTimeout,
                                            int socketTimeout,
                                            int maxRetries,
                                            int injectSocketTimeout,
                                            AtomicBoolean canceling,
                                            boolean includeRetryParameters,
                                            boolean retryOnHTTP403,
                                            HttpClientSettingsKey ocspAndProxyKey,
                                            ExecTimeTelemetryData execTimeData,
                                            SFBaseSession sfSession)
                                     throws SnowflakeSQLException,
                                            IOException
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator timeout
        socketTimeout - socket timeout (in ms)
        maxRetries - retry count for the request
        injectSocketTimeout - injecting socket timeout
        canceling - canceling?
        includeRetryParameters - whether to include retry parameters in retried requests
        retryOnHTTP403 - whether to retry on HTTP 403 or not
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        execTimeData - query execution time telemetry data object
        sfSession - the session associated with the request
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeRequest

        @Deprecated
        public static String executeRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                            int retryTimeout,
                                            int authTimeout,
                                            int socketTimeout,
                                            int maxRetries,
                                            int injectSocketTimeout,
                                            AtomicBoolean canceling,
                                            boolean includeRetryParameters,
                                            boolean retryOnHTTP403,
                                            HttpClientSettingsKey ocspAndProxyKey,
                                            ExecTimeTelemetryData execTimeData,
                                            RetryContextManager retryContextManager)
                                     throws SnowflakeSQLException,
                                            IOException
        Deprecated.
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator timeout
        socketTimeout - socket timeout (in ms)
        maxRetries - retry count for the request
        injectSocketTimeout - injecting socket timeout
        canceling - canceling?
        includeRetryParameters - whether to include retry parameters in retried requests
        retryOnHTTP403 - whether to retry on HTTP 403 or not
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        execTimeData - query execution time telemetry data object
        retryContextManager - RetryContext used to customize retry handling functionality
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs
      • executeRequest

        @SnowflakeJdbcInternalApi
        public static String executeRequest​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                            int retryTimeout,
                                            int authTimeout,
                                            int socketTimeout,
                                            int maxRetries,
                                            int injectSocketTimeout,
                                            AtomicBoolean canceling,
                                            boolean includeRetryParameters,
                                            boolean retryOnHTTP403,
                                            HttpClientSettingsKey ocspAndProxyKey,
                                            ExecTimeTelemetryData execTimeData,
                                            RetryContextManager retryContextManager,
                                            SFBaseSession sfSession)
                                     throws SnowflakeSQLException,
                                            IOException
        Executes an HTTP request for Snowflake.
        Parameters:
        httpRequest - HttpRequestBase
        retryTimeout - retry timeout
        authTimeout - authenticator timeout
        socketTimeout - socket timeout (in ms)
        maxRetries - retry count for the request
        injectSocketTimeout - injecting socket timeout
        canceling - canceling?
        includeRetryParameters - whether to include retry parameters in retried requests
        retryOnHTTP403 - whether to retry on HTTP 403 or not
        ocspAndProxyKey - OCSP mode and proxy settings for httpclient
        execTimeData - query execution time telemetry data object
        retryContextManager - RetryContext used to customize retry handling functionality
        sfSession - the session associated with the request
        Returns:
        response
        Throws:
        SnowflakeSQLException - if Snowflake error occurs
        IOException - raises if a general IO error occurs