org.apache.solr.client.solrj.impl

## Class HttpClientUtil

- java.lang.Object
- - org.apache.solr.client.solrj.impl.HttpClientUtil

-     public class HttpClientUtil
      extends Object

  Utility class for creating/configuring httpclient instances.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `HttpClientUtil.HttpClientFactory`

  - ### Field Summary

    Fields
    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`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpClientUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    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` | `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. use `addConfigurer(HttpClientConfigurer)`
    `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

    - ### 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

    - #### SYS_PROP_CHECK_PEER_NAME

          public static final String SYS_PROP_CHECK_PEER_NAME

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### HttpClientUtil

          public HttpClientUtil()

  - ### Method Detail

    - #### setConfigurer

          @Deprecated
          public static void setConfigurer(HttpClientConfigurer newConfigurer)

      Deprecated. use `addConfigurer(HttpClientConfigurer)`
      Add a `HttpClientConfigurer` class used to configure the http clients.

    - #### addConfigurer

          public static void addConfigurer(HttpClientConfigurer newConfigurer)

      Add a `HttpClientConfigurer` to the list of configurers used to create http clients

    - #### removeConfigurer

          public static void removeConfigurer(HttpClientConfigurer configurer)

      Remove a `HttpClientConfigurer` from the list of configurers used to create http clients

    - #### resetConfigurers

          public static void resetConfigurers()

    - #### createClient

          public static org.apache.http.impl.client.CloseableHttpClient 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.impl.client.CloseableHttpClient 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.

    - #### close

          public static void close(org.apache.http.client.HttpClient httpClient)

    - #### addRequestInterceptor

          public static void addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)

    - #### removeRequestInterceptor

          public static void removeRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)

    - #### 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.

    - #### setHostNameVerifier

          public static void setHostNameVerifier(org.apache.http.impl.client.DefaultHttpClient httpClient,
                                                 org.apache.http.conn.ssl.X509HostnameVerifier hostNameVerifier)

    - #### setStaleCheckingEnabled

          public static void setStaleCheckingEnabled(org.apache.http.client.HttpClient httpClient,
                                                     boolean enabled)

    - #### setTcpNoDelay

          public static void setTcpNoDelay(org.apache.http.client.HttpClient httpClient,
                                           boolean tcpNoDelay)

    - #### createNewHttpClientRequestContext

          public static org.apache.http.client.protocol.HttpClientContext createNewHttpClientRequestContext()

      Create a HttpClientContext object and `HttpClientContext.setUserToken(Object)` to an internal singleton. It allows to reuse underneath `HttpClient` in connection pools if client authentication is enabled.

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