if (multiThreadedHttpClient)
connManager = new ThreadSafeClientConnManager(httpParams, registry);
else
connManager = new SingleClientConnManager(httpParams, registry);
DefaultHttpClient client = new DefaultHttpClient(connManager, httpParams);
client.getParams().setParameter(AllClientPNames.MAX_REDIRECTS,
new Integer(maxRedirects));
client.getParams().setParameter(AllClientPNames.ALLOW_CIRCULAR_REDIRECTS,
allowCircularRedirects);
client.getParams().setParameter(AllClientPNames.SO_TIMEOUT,
new Integer(socketTimeout));
client.getParams().setParameter(AllClientPNames.CONNECTION_TIMEOUT,
new Integer(connTimeout));
if (cookiePolicy == null)
{
client.setCookieStore(null);
}
else
{
client.getParams().setParameter(AllClientPNames.COOKIE_POLICY,
cookiePolicy);
}
if (proxyProperties != null)
{
HttpHost proxy = new HttpHost(
proxyProperties.getProxyHostName(),
proxyProperties.getProxyPort());
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
//now set headers for auth
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
Credentials credentials = proxyProperties.getCredentials();
client.getCredentialsProvider().setCredentials(authScope, credentials);
}
return client;
}