* so need to ensure that any items used in its equals/hashcode methods are
* not changed after use, i.e.:
* host, port, protocol, localAddress, proxy
*
*/
HostConfiguration hc = new HostConfiguration();
hc.setHost(host, port, protocol); // All needed to ensure re-usablility
// Set up the local address if one exists
if (localAddress != null){
hc.setLocalAddress(localAddress);
} else {
final String ipSource = getIpSource();
if (ipSource.length() > 0) {// Use special field ip source address (for pseudo 'ip spoofing')
InetAddress inetAddr = InetAddress.getByName(ipSource);
hc.setLocalAddress(inetAddr);
}
}
final String proxyHost = getProxyHost();
final int proxyPort = getProxyPortInt();
boolean useStaticProxy = isStaticProxy(host);
boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);
if (useDynamicProxy){
hc.setProxy(proxyHost, proxyPort);
useStaticProxy = false; // Dynamic proxy overrules static proxy
} else if (useStaticProxy) {
if (log.isDebugEnabled()){
log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
}
hc.setProxy(PROXY_HOST, PROXY_PORT);
}
Map<HostConfiguration, HttpClient> map = httpClients.get();
// N.B. HostConfiguration.equals() includes proxy settings in the compare.
HttpClient httpClient = map.get(hc);