Package net.snowflake.client.core
Class HttpUtil
- java.lang.Object
-
- net.snowflake.client.core.HttpUtil
-
public class HttpUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpUtil.HttpInputStream
-
Field Summary
Fields Modifier and Type Field Description static Map<HttpClientSettingsKey,org.apache.http.impl.client.CloseableHttpClient>
httpClient
The unique httpClient shared by all connections.static String
JDBC_MAX_CONNECTIONS_PER_ROUTE_PROPERTY
static String
JDBC_MAX_CONNECTIONS_PROPERTY
static String
JDBC_TTL
-
Constructor Summary
Constructors Constructor Description HttpUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static org.apache.http.impl.client.CloseableHttpClient
buildHttpClient(HttpClientSettingsKey key, File ocspCacheFile, boolean downloadUnCompressed)
Build an Http client using our set of default.static void
closeExpiredAndIdleConnections()
static String
executeGeneralRequest(org.apache.http.client.methods.HttpRequestBase httpRequest, int retryTimeout, int authTimeout, int socketTimeout, int retryCount, HttpClientSettingsKey ocspAndProxyAndGzipKey)
Executes a HTTP request for Snowflake.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)
Executes a HTTP request for Snowflakestatic 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)
Executes a HTTP request for Snowflake.static Duration
getConnectionTimeout()
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.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.static long
getDownloadedConditionTimeoutInSeconds()
static org.apache.http.impl.client.CloseableHttpClient
getHttpClient(HttpClientSettingsKey ocspAndProxyKey)
Gets HttpClient with insecureMode falsestatic org.apache.http.impl.client.CloseableHttpClient
getHttpClientWithoutDecompression(HttpClientSettingsKey ocspAndProxyKey)
Gets HttpClient with insecureMode false and disabling decompressionstatic 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.static Duration
getSocketTimeout()
static org.apache.http.impl.client.CloseableHttpClient
initHttpClient(HttpClientSettingsKey key, File ocspCacheFile)
Accessor for the HTTP client singleton.static org.apache.http.impl.client.CloseableHttpClient
initHttpClientWithoutDecompression(HttpClientSettingsKey key, File ocspCacheFile)
Accessor for the HTTP client singleton.static boolean
isSocksProxyDisabled()
Returns whether the SOCKS proxy is disabled for this JVMstatic void
setConnectionTimeout(int timeout)
static void
setProxyForAzure(HttpClientSettingsKey key, com.microsoft.azure.storage.OperationContext opContext)
A static function to set Azure proxy params when there is a valid sessionstatic void
setProxyForS3(HttpClientSettingsKey key, com.amazonaws.ClientConfiguration clientConfig)
Deprecated.static void
setRequestConfig(org.apache.http.client.config.RequestConfig requestConfig)
static void
setSessionlessProxyForAzure(Properties proxyProperties, com.microsoft.azure.storage.OperationContext opContext)
A static function to set Azure proxy params for sessionless connections using the proxy params from the StageInfostatic void
setSessionlessProxyForS3(Properties proxyProperties, com.amazonaws.ClientConfiguration clientConfig)
Deprecated.static void
setSocketTimeout(int timeout)
static void
setSocksProxyDisabled(boolean socksProxyDisabled)
Enables/disables use of the SOCKS proxy when creating socketsstatic void
updateRoutePlanner(HttpClientSettingsKey key)
-
-
-
Field Detail
-
JDBC_TTL
public static final String JDBC_TTL
- See Also:
- Constant Field Values
-
JDBC_MAX_CONNECTIONS_PROPERTY
public static final String JDBC_MAX_CONNECTIONS_PROPERTY
- See Also:
- Constant Field Values
-
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]
-
-
Method Detail
-
getConnectionTimeout
@SnowflakeJdbcInternalApi public static Duration getConnectionTimeout()
-
getSocketTimeout
@SnowflakeJdbcInternalApi public static Duration getSocketTimeout()
-
setConnectionTimeout
@SnowflakeJdbcInternalApi public static void setConnectionTimeout(int timeout)
-
setSocketTimeout
@SnowflakeJdbcInternalApi public static void setSocketTimeout(int timeout)
-
getDownloadedConditionTimeoutInSeconds
public static long getDownloadedConditionTimeoutInSeconds()
-
closeExpiredAndIdleConnections
public static void closeExpiredAndIdleConnections()
-
setProxyForS3
@Deprecated public static void setProxyForS3(HttpClientSettingsKey key, com.amazonaws.ClientConfiguration clientConfig)
Deprecated.A static function to set S3 proxy params when there is a valid session- Parameters:
key
- key to HttpClient map containing OCSP and proxy infoclientConfig
- the configuration needed by S3 to set the proxy
-
setSessionlessProxyForS3
@Deprecated public static void setSessionlessProxyForS3(Properties proxyProperties, com.amazonaws.ClientConfiguration clientConfig) throws SnowflakeSQLException
Deprecated.A static function to set S3 proxy params for sessionless connections using the proxy params from the StageInfo- Parameters:
proxyProperties
- proxy propertiesclientConfig
- the configuration needed by S3 to set the proxy- Throws:
SnowflakeSQLException
-
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 propertiesopContext
- the configuration needed by Azure to set the proxy- Throws:
SnowflakeSQLException
-
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 infoopContext
- 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 nullocspCacheFile
- 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
-
updateRoutePlanner
public static void updateRoutePlanner(HttpClientSettingsKey key)
-
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
-
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 HttpClientocspCacheFile
- 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 HttpClientocspCacheFile
- OCSP response cache file name. if null, the default file will be used.- 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-secondswithoutCookies
- - 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-secondswithoutCookies
- - 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
public static String executeGeneralRequest(org.apache.http.client.methods.HttpRequestBase httpRequest, int retryTimeout, int authTimeout, int socketTimeout, int retryCount, HttpClientSettingsKey ocspAndProxyAndGzipKey) throws SnowflakeSQLException, IOException
Executes a HTTP request for Snowflake.- Parameters:
httpRequest
- HttpRequestBaseretryTimeout
- retry timeoutauthTimeout
- authenticator specific timeoutsocketTimeout
- socket timeout (in ms)retryCount
- retry count for the requestocspAndProxyAndGzipKey
- OCSP mode and proxy settings for httpclient- Returns:
- response
- Throws:
SnowflakeSQLException
- if Snowflake error occursIOException
- raises if a general IO error occurs
-
executeGeneralRequest
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
Executes a HTTP request for Snowflake- Parameters:
httpRequest
- HttpRequestBaseretryTimeout
- retry timeoutauthTimeout
- authenticator specific timeoutsocketTimeout
- socket timeout (in ms)retryCount
- retry count for the requesthttpClient
- client object used to communicate with other machine- Returns:
- response
- Throws:
SnowflakeSQLException
- if Snowflake error occursIOException
- raises if a general IO error occurs
-
executeRequest
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
Executes a HTTP request for Snowflake.- Parameters:
httpRequest
- HttpRequestBaseretryTimeout
- retry timeoutauthTimeout
- authenticator timeoutsocketTimeout
- socket timeout (in ms)maxRetries
- retry count for the requestinjectSocketTimeout
- injecting socket timeoutcanceling
- canceling?includeRetryParameters
- whether to include retry parameters in retried requestsretryOnHTTP403
- whether to retry on HTTP 403 or notocspAndProxyKey
- OCSP mode and proxy settings for httpclient- Returns:
- response
- Throws:
SnowflakeSQLException
- if Snowflake error occursIOException
- raises if a general IO error occurs
-
-