Class HttpComponents5ClientFactory

All Implemented Interfaces:

public class HttpComponents5ClientFactory extends Object implements org.springframework.beans.factory.FactoryBean<org.apache.hc.client5.http.impl.classic.CloseableHttpClient>
FactoryBean to set up a CloseableHttpClient using HttpComponents HttpClient 5.
Lars Uffmann
  • Field Details

    • ANY

      public static final org.apache.hc.client5.http.auth.AuthScope ANY
      AuthScope to match any Host.

      NOTE: ANY was removed from AuthScope in HttpComponents 5.0. This value object will easy migration from HttpComponents 4. Consider using a ClientInterceptor to implement http client agnostic preemptive basic auth.

      See Also:
      • AuthScope(String, String, int, String, String)
  • Constructor Details

    • HttpComponents5ClientFactory

      public HttpComponents5ClientFactory()
  • Method Details

    • setCredentials

      public void setCredentials(org.apache.hc.client5.http.auth.Credentials credentials)
      Sets the credentials to be used. If not set, no authentication is done.
      See Also:
      • UsernamePasswordCredentials
      • NTCredentials
    • setAuthScope

      public void setAuthScope(org.apache.hc.client5.http.auth.AuthScope authScope)
      Sets the authentication scope to be used. Only used when the credentials property has been set.

      By default, ANY is used.

      See Also:
    • setConnectionTimeout

      public void setConnectionTimeout(Duration timeout)
      Sets the timeout until a connection is established. A value of 0 means never timeout.
      timeout - the timeout value
    • setReadTimeout

      public void setReadTimeout(Duration timeout)
      Set the socket read timeout for the underlying HttpClient. A value of 0 means never timeout.
      timeout - the timeout value
    • setMaxTotalConnections

      public void setMaxTotalConnections(int maxTotalConnections)
      Sets the maximum number of connections allowed for the underlying HttpClient.
      maxTotalConnections - the maximum number of connections allowed
    • setMaxConnectionsPerHost

      public void setMaxConnectionsPerHost(Map<String,String> maxConnectionsPerHost)
      Sets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections per host can be set in a form accepted by the java.util.Properties class, like as follows:

      The host can be specified as a URI (with scheme and port).

      maxConnectionsPerHost - a properties object specifying the maximum number of connection
    • isSingleton

      public boolean isSingleton()
      Specified by:
      isSingleton in interface org.springframework.beans.factory.FactoryBean<org.apache.hc.client5.http.impl.classic.CloseableHttpClient>
    • getObject

      public org.apache.hc.client5.http.impl.classic.CloseableHttpClient getObject() throws Exception
      Specified by:
      getObject in interface org.springframework.beans.factory.FactoryBean<org.apache.hc.client5.http.impl.classic.CloseableHttpClient>
    • getObjectType

      public Class<?> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean<org.apache.hc.client5.http.impl.classic.CloseableHttpClient>
    • setClientBuilderCustomizer

      public void setClientBuilderCustomizer(HttpComponents5ClientFactory.HttpClientBuilderCustomizer clientBuilderCustomizer)
    • setConnectionManagerBuilderCustomizer

      public void setConnectionManagerBuilderCustomizer(HttpComponents5ClientFactory.PoolingHttpClientConnectionManagerBuilderCustomizer connectionManagerBuilderCustomizer)