package org.apache.commons.httpclient.contrib.ssl;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpHost;
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
public class HttpHostFactory
{
public static final HttpHostFactory DEFAULT = new HttpHostFactory(null,
new Protocol(new String(HttpsURL.DEFAULT_SCHEME),
(ProtocolSocketFactory) new EasySSLProtocolSocketFactory(),
HttpsURL.DEFAULT_PORT));
public HttpHostFactory(Protocol httpProtocol, Protocol httpsProtocol)
{
this.httpProtocol = httpProtocol;
this.httpsProtocol = httpsProtocol;
}
protected final Protocol httpProtocol;
protected final Protocol httpsProtocol;
public HttpHost getHost(HostConfiguration old, String scheme, String host, int port)
{
return new HttpHost(host, port, getProtocol(old, scheme, host, port));
}
protected Protocol getProtocol(HostConfiguration old, String scheme, String host, int port)
{
final Protocol oldProtocol = old.getProtocol();
if (oldProtocol != null) {
final String oldScheme = oldProtocol.getScheme();
if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
return oldProtocol;
}
}
Protocol newProtocol = (scheme != null && scheme.toLowerCase().endsWith("s")) ? httpsProtocol
: httpProtocol;
if (newProtocol == null) {
newProtocol = Protocol.getProtocol(scheme);
}
return newProtocol;
}
}