HttpClientParams httpClientParams = new HttpClientParams();
httpClientParams.setParameter(HttpMethodParams.USER_AGENT, userAgent);
httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, new RetryHandler());
/* Set host configuration */
HostConfiguration hostConfiguration = new HostConfiguration();
/* Set connection manager parameters */
HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
connectionManagerParams.setConnectionTimeout(config.getConnectionTimeout());
connectionManagerParams.setSoTimeout(config.getSocketTimeout());
connectionManagerParams.setStaleCheckingEnabled(true);
connectionManagerParams.setTcpNoDelay(true);
connectionManagerParams.setMaxTotalConnections(config.getMaxConnections());
connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, config.getMaxConnections());
int socketSendBufferSizeHint = config.getSocketBufferSizeHints()[0];
if (socketSendBufferSizeHint > 0) {
connectionManagerParams.setSendBufferSize(socketSendBufferSizeHint);
}
int socketReceiveBufferSizeHint = config.getSocketBufferSizeHints()[1];
if (socketReceiveBufferSizeHint > 0) {
connectionManagerParams.setReceiveBufferSize(socketReceiveBufferSizeHint);
}
/* Set connection manager */
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.setParams(connectionManagerParams);
httpClient = new org.apache.commons.httpclient.HttpClient(
httpClientParams, connectionManager);
/* Set proxy if configured */
String proxyHost = config.getProxyHost();
int proxyPort = config.getProxyPort();
if (proxyHost != null && proxyPort > 0) {
log.info("Configuring Proxy. Proxy Host: " + proxyHost + " "
+ "Proxy Port: " + proxyPort);
hostConfiguration.setProxy(proxyHost, proxyPort);
String proxyUsername = config.getProxyUsername();
String proxyPassword = config.getProxyPassword();
if (proxyUsername != null && proxyPassword != null) {
AuthScope authScope = new AuthScope(proxyHost, proxyPort);