public class HttpClientUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
HttpClientUtil.HttpClientFactory |
Modifier and Type | Field and Description |
---|---|
static String |
PROP_ALLOW_COMPRESSION |
static String |
PROP_BASIC_AUTH_PASS |
static String |
PROP_BASIC_AUTH_USER |
static String |
PROP_CONNECTION_TIMEOUT |
static String |
PROP_FOLLOW_REDIRECTS |
static String |
PROP_MAX_CONNECTIONS |
static String |
PROP_MAX_CONNECTIONS_PER_HOST |
static String |
PROP_SO_TIMEOUT |
static String |
PROP_USE_RETRY |
static String |
SYS_PROP_CHECK_PEER_NAME |
static String |
SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY
A Java system property to select the HttpClientConfigurer used for
configuring the HttpClientConfigurer instance by default.
|
Constructor and Description |
---|
HttpClientUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
addConfigurer(HttpClientConfigurer newConfigurer)
Add a
HttpClientConfigurer to the list of configurers used
to create http clients |
static void |
addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor) |
static void |
clearRequestInterceptors() |
static void |
close(org.apache.http.client.HttpClient httpClient) |
static void |
configureClient(org.apache.http.impl.client.DefaultHttpClient httpClient,
SolrParams config)
Configures
DefaultHttpClient , only sets parameters if they are
present in config. |
static org.apache.http.impl.client.CloseableHttpClient |
createClient(SolrParams params)
Creates new http client by using the provided configuration.
|
static org.apache.http.impl.client.CloseableHttpClient |
createClient(SolrParams params,
org.apache.http.conn.ClientConnectionManager cm)
Creates new http client by using the provided configuration.
|
static org.apache.http.client.protocol.HttpClientContext |
createNewHttpClientRequestContext()
Create a HttpClientContext object and
HttpClientContext.setUserToken(Object)
to an internal singleton. |
static void |
removeConfigurer(HttpClientConfigurer configurer)
Remove a
HttpClientConfigurer from the list of configurers used
to create http clients |
static void |
removeRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor) |
static void |
resetConfigurers() |
static void |
setAllowCompression(org.apache.http.impl.client.DefaultHttpClient httpClient,
boolean allowCompression)
Control HTTP payload compression.
|
static void |
setBasicAuth(org.apache.http.impl.client.DefaultHttpClient httpClient,
String basicAuthUser,
String basicAuthPass)
Set http basic auth information.
|
static void |
setConfigurer(HttpClientConfigurer newConfigurer)
Deprecated.
|
static void |
setConnectionTimeout(org.apache.http.client.HttpClient httpClient,
int timeout)
Set connection timeout.
|
static void |
setFollowRedirects(org.apache.http.client.HttpClient httpClient,
boolean followRedirects)
Set follow redirects.
|
static void |
setHostNameVerifier(org.apache.http.impl.client.DefaultHttpClient httpClient,
org.apache.http.conn.ssl.X509HostnameVerifier hostNameVerifier) |
static void |
setMaxConnections(org.apache.http.client.HttpClient httpClient,
int max)
Set max total connections allowed.
|
static void |
setMaxConnectionsPerHost(org.apache.http.client.HttpClient httpClient,
int max)
Set max connections allowed per host.
|
static void |
setSoTimeout(org.apache.http.client.HttpClient httpClient,
int timeout)
Defines the socket timeout (SO_TIMEOUT) in milliseconds.
|
static void |
setStaleCheckingEnabled(org.apache.http.client.HttpClient httpClient,
boolean enabled) |
static void |
setTcpNoDelay(org.apache.http.client.HttpClient httpClient,
boolean tcpNoDelay) |
static void |
setUseRetry(org.apache.http.impl.client.DefaultHttpClient httpClient,
boolean useRetry)
Control retry handler
|
public static final String PROP_SO_TIMEOUT
public static final String PROP_CONNECTION_TIMEOUT
public static final String PROP_MAX_CONNECTIONS_PER_HOST
public static final String PROP_MAX_CONNECTIONS
public static final String PROP_USE_RETRY
public static final String PROP_ALLOW_COMPRESSION
public static final String PROP_FOLLOW_REDIRECTS
public static final String PROP_BASIC_AUTH_USER
public static final String PROP_BASIC_AUTH_PASS
public static final String SYS_PROP_CHECK_PEER_NAME
public static final String SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY
@Deprecated public static void setConfigurer(HttpClientConfigurer newConfigurer)
addConfigurer(HttpClientConfigurer)
HttpClientConfigurer
class used to configure the http
clients.public static void addConfigurer(HttpClientConfigurer newConfigurer)
HttpClientConfigurer
to the list of configurers used
to create http clientspublic static void removeConfigurer(HttpClientConfigurer configurer)
HttpClientConfigurer
from the list of configurers used
to create http clientspublic static void resetConfigurers()
public static org.apache.http.impl.client.CloseableHttpClient createClient(SolrParams params)
params
- http client configuration, if null a client with default
configuration (no additional configuration) is created.public static org.apache.http.impl.client.CloseableHttpClient createClient(SolrParams params, org.apache.http.conn.ClientConnectionManager cm)
public static void configureClient(org.apache.http.impl.client.DefaultHttpClient httpClient, SolrParams config)
DefaultHttpClient
, only sets parameters if they are
present in config.public static void close(org.apache.http.client.HttpClient httpClient)
public static void addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
public static void removeRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
public static void clearRequestInterceptors()
public static void setAllowCompression(org.apache.http.impl.client.DefaultHttpClient httpClient, boolean allowCompression)
allowCompression
- true will enable compression (needs support from server), false
will disable compression.public static void setBasicAuth(org.apache.http.impl.client.DefaultHttpClient httpClient, String basicAuthUser, String basicAuthPass)
public static void setMaxConnectionsPerHost(org.apache.http.client.HttpClient httpClient, int max)
ThreadSafeClientConnManager
or
PoolingClientConnectionManager
is used.public static void setMaxConnections(org.apache.http.client.HttpClient httpClient, int max)
ThreadSafeClientConnManager
or
PoolingClientConnectionManager
is used.public static void setSoTimeout(org.apache.http.client.HttpClient httpClient, int timeout)
timeout
- timeout in millisecondspublic static void setUseRetry(org.apache.http.impl.client.DefaultHttpClient httpClient, boolean useRetry)
useRetry
- when false the client will not try to retry failed requests.public static void setConnectionTimeout(org.apache.http.client.HttpClient httpClient, int timeout)
timeout
- connection Timeout in millisecondspublic static void setFollowRedirects(org.apache.http.client.HttpClient httpClient, boolean followRedirects)
followRedirects
- When true the client will follow redirects.public static void setHostNameVerifier(org.apache.http.impl.client.DefaultHttpClient httpClient, org.apache.http.conn.ssl.X509HostnameVerifier hostNameVerifier)
public static void setStaleCheckingEnabled(org.apache.http.client.HttpClient httpClient, boolean enabled)
public static void setTcpNoDelay(org.apache.http.client.HttpClient httpClient, boolean tcpNoDelay)
public static org.apache.http.client.protocol.HttpClientContext createNewHttpClientRequestContext()
HttpClientContext.setUserToken(Object)
to an internal singleton. It allows to reuse underneath HttpClient
in connection pools if client authentication is enabled.Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.