org.apache.solr.client.solrj.impl
Class HttpClientUtil

java.lang.Object
  extended by org.apache.solr.client.solrj.impl.HttpClientUtil

public class HttpClientUtil
extends Object

Utility class for creating/configuring httpclient instances.


Field Summary
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
           
 
Method Summary
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.client.HttpClient createClient(SolrParams params)
          Creates new http client by using the provided configuration.
static org.apache.http.client.HttpClient createClient(SolrParams params, org.apache.http.conn.ClientConnectionManager cm)
          Creates new http client by using the provided configuration.
static HttpClientConfigurer getConfigurer()
           
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)
          Replace the HttpClientConfigurer class used in configuring the http clients with a custom implementation.
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 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 setUseRetry(org.apache.http.impl.client.DefaultHttpClient httpClient, boolean useRetry)
          Control retry handler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_SO_TIMEOUT

public static final String PROP_SO_TIMEOUT
See Also:
Constant Field Values

PROP_CONNECTION_TIMEOUT

public static final String PROP_CONNECTION_TIMEOUT
See Also:
Constant Field Values

PROP_MAX_CONNECTIONS_PER_HOST

public static final String PROP_MAX_CONNECTIONS_PER_HOST
See Also:
Constant Field Values

PROP_MAX_CONNECTIONS

public static final String PROP_MAX_CONNECTIONS
See Also:
Constant Field Values

PROP_USE_RETRY

public static final String PROP_USE_RETRY
See Also:
Constant Field Values

PROP_ALLOW_COMPRESSION

public static final String PROP_ALLOW_COMPRESSION
See Also:
Constant Field Values

PROP_FOLLOW_REDIRECTS

public static final String PROP_FOLLOW_REDIRECTS
See Also:
Constant Field Values

PROP_BASIC_AUTH_USER

public static final String PROP_BASIC_AUTH_USER
See Also:
Constant Field Values

PROP_BASIC_AUTH_PASS

public static final String PROP_BASIC_AUTH_PASS
See Also:
Constant Field Values
Method Detail

setConfigurer

public static void setConfigurer(HttpClientConfigurer newConfigurer)
Replace the HttpClientConfigurer class used in configuring the http clients with a custom implementation.


getConfigurer

public static HttpClientConfigurer getConfigurer()

createClient

public static org.apache.http.client.HttpClient createClient(SolrParams params)
Creates new http client by using the provided configuration.

Parameters:
params - http client configuration, if null a client with default configuration (no additional configuration) is created.

createClient

public static org.apache.http.client.HttpClient createClient(SolrParams params,
                                                             org.apache.http.conn.ClientConnectionManager cm)
Creates new http client by using the provided configuration.


configureClient

public static void configureClient(org.apache.http.impl.client.DefaultHttpClient httpClient,
                                   SolrParams config)
Configures DefaultHttpClient, only sets parameters if they are present in config.


setAllowCompression

public static void setAllowCompression(org.apache.http.impl.client.DefaultHttpClient httpClient,
                                       boolean allowCompression)
Control HTTP payload compression.

Parameters:
allowCompression - true will enable compression (needs support from server), false will disable compression.

setBasicAuth

public static void setBasicAuth(org.apache.http.impl.client.DefaultHttpClient httpClient,
                                String basicAuthUser,
                                String basicAuthPass)
Set http basic auth information. If basicAuthUser or basicAuthPass is null the basic auth configuration is cleared. Currently this is not preemtive authentication. So it is not currently possible to do a post request while using this setting.


setMaxConnectionsPerHost

public static void setMaxConnectionsPerHost(org.apache.http.client.HttpClient httpClient,
                                            int max)
Set max connections allowed per host. This call will only work when ThreadSafeClientConnManager or PoolingClientConnectionManager is used.


setMaxConnections

public static void setMaxConnections(org.apache.http.client.HttpClient httpClient,
                                     int max)
Set max total connections allowed. This call will only work when ThreadSafeClientConnManager or PoolingClientConnectionManager is used.


setSoTimeout

public static void setSoTimeout(org.apache.http.client.HttpClient httpClient,
                                int timeout)
Defines the socket timeout (SO_TIMEOUT) in milliseconds. A timeout value of zero is interpreted as an infinite timeout.

Parameters:
timeout - timeout in milliseconds

setUseRetry

public static void setUseRetry(org.apache.http.impl.client.DefaultHttpClient httpClient,
                               boolean useRetry)
Control retry handler

Parameters:
useRetry - when false the client will not try to retry failed requests.

setConnectionTimeout

public static void setConnectionTimeout(org.apache.http.client.HttpClient httpClient,
                                        int timeout)
Set connection timeout. A timeout value of zero is interpreted as an infinite timeout.

Parameters:
timeout - connection Timeout in milliseconds

setFollowRedirects

public static void setFollowRedirects(org.apache.http.client.HttpClient httpClient,
                                      boolean followRedirects)
Set follow redirects.

Parameters:
followRedirects - When true the client will follow redirects.


Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.