Package org.alfresco.util
Class HttpClientHelper
- java.lang.Object
-
- org.alfresco.util.HttpClientHelper
-
public class HttpClientHelper extends java.lang.ObjectHelper 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 inRemoteClientbut 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 HttpClientHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.apache.commons.httpclient.CredentialscreateProxyCredentials(java.lang.String proxyUserProperty, java.lang.String proxyPasswordProperty)Create the proxy credentials for the given proxy user and password properties.static org.apache.commons.httpclient.ProxyHostcreateProxyHost(java.lang.String hostProperty, java.lang.String portProperty, int defaultPort)Create proxy host for the given system host and port properties.static org.apache.commons.httpclient.HttpClientgetHttpClient()Returns an initialised HttpClient instance for the current thread, which will have been configured for optimal settingsstatic booleanrequiresProxy(java.lang.String targetHost)Return true unless the given target host is specified in thehttp.nonProxyHostssystem property (used for both protocols, http and https).
-
-
-
Method Detail
-
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(java.lang.String hostProperty, java.lang.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(java.lang.String proxyUserProperty, java.lang.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
public static boolean requiresProxy(java.lang.String targetHost)
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
-
-