Package org.alfresco.util
Class HttpClientHelper
java.lang.Object
org.alfresco.util.HttpClientHelper
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.commons.httpclient.CredentialscreateProxyCredentials(String proxyUserProperty, String proxyPasswordProperty) Create the proxy credentials for the given proxy user and password properties.static org.apache.commons.httpclient.ProxyHostcreateProxyHost(String hostProperty, String portProperty, int defaultPort) Create proxy host for the given system host and port properties.static org.apache.commons.httpclient.HttpClientReturns an initialised HttpClient instance for the current thread, which will have been configured for optimal settingsstatic booleanrequiresProxy(String targetHost) Return true unless the given target host is specified in thehttp.nonProxyHostssystem property (used for both protocols, http and https).
-
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.proxyHostorhttps.proxyHost)portProperty- the name of the system property for the proxy server port (http.proxyPortorhttps.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 userproxyPasswordProperty- the name of the system property for the proxy password- Returns:
- Credentials if appropriate properties have been set, null otherwise
-
requiresProxy
Return true unless the given target host is specified in thehttp.nonProxyHostssystem 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
-