Class HttpClientHelper

java.lang.Object
org.alfresco.util.HttpClientHelper

public class HttpClientHelper extends Object
Helper class to provide access to Thread Local instances of HttpClient. These instances will have been set up in a way that optimises the performance for one thread doing a fetch and then using the result. You must call releaseConnection() when you're done with the request, otherwise things will break for the next request in this thread! TODO Merge me back to Spring Surf, which is where this code has been pulled out from (was in RemoteClient but not available externally) This class also provides support for creating proxy configurations, taking into account System properties like:

  • http.proxyHost
  • http.proxyPort
  • http.proxyUser
  • http.proxyPassword
  • http.nonProxyHosts
  • https.proxyHost
  • https.proxyPort
  • https.proxyUser
  • https.proxyPassword

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.commons.httpclient.Credentials
    createProxyCredentials(String proxyUserProperty, String proxyPasswordProperty)
    Create the proxy credentials for the given proxy user and password properties.
    static org.apache.commons.httpclient.ProxyHost
    createProxyHost(String hostProperty, String portProperty, int defaultPort)
    Create proxy host for the given system host and port properties.
    static org.apache.commons.httpclient.HttpClient
    Returns an initialised HttpClient instance for the current thread, which will have been configured for optimal settings
    static boolean
    requiresProxy(String targetHost)
    Return true unless the given target host is specified in the http.nonProxyHosts system property (used for both protocols, http and https).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpClientHelper

      public HttpClientHelper()
  • Method Details

    • getHttpClient

      public static org.apache.commons.httpclient.HttpClient getHttpClient()
      Returns an initialised HttpClient instance for the current thread, which will have been configured for optimal settings
    • createProxyHost

      public static org.apache.commons.httpclient.ProxyHost createProxyHost(String hostProperty, String portProperty, int defaultPort)
      Create proxy host for the given system host and port properties. If the properties are not set, no proxy will be created.
      Parameters:
      hostProperty - the name of the system property for the proxy server (http.proxyHost or https.proxyHost)
      portProperty - the name of the system property for the proxy server port (http.proxyPort or https.proxyPort)
      defaultPort -
      Returns:
      ProxyHost if appropriate properties have been set, null otherwise
    • createProxyCredentials

      public static org.apache.commons.httpclient.Credentials createProxyCredentials(String proxyUserProperty, String proxyPasswordProperty)
      Create the proxy credentials for the given proxy user and password properties. If the properties are not set, not credentials will be created.
      Parameters:
      proxyUserProperty - the name of the system property for the proxy user
      proxyPasswordProperty - the name of the system property for the proxy password
      Returns:
      Credentials if appropriate properties have been set, null otherwise
    • requiresProxy

      public static boolean requiresProxy(String targetHost)
      Return true unless the given target host is specified in the http.nonProxyHosts system property (used for both protocols, http and https). See Networking Properties.
      Parameters:
      targetHost - Non-null host name to verify
      Returns:
      true if not specified in the list, false if it is specified and therefore should be excluded from proxy