1 package org.apache.commons.httpclient.contrib.ssl; 2 3 import org.apache.commons.httpclient.HostConfiguration; 4 import org.apache.commons.httpclient.HttpHost; 5 import org.apache.commons.httpclient.HttpsURL; 6 import org.apache.commons.httpclient.protocol.Protocol; 7 import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; 8 9 10 public class HttpHostFactory 11 { 12 13 public static final HttpHostFactory DEFAULT = new HttpHostFactory(null, new Protocol(new String (HttpsURL.DEFAULT_SCHEME), 15 (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 16 HttpsURL.DEFAULT_PORT)); 17 18 public HttpHostFactory(Protocol httpProtocol, Protocol httpsProtocol) 19 { 20 this.httpProtocol = httpProtocol; 21 this.httpsProtocol = httpsProtocol; 22 } 23 24 protected final Protocol httpProtocol; 25 26 protected final Protocol httpsProtocol; 27 28 29 public HttpHost getHost(HostConfiguration old, String scheme, String host, int port) 30 { 31 return new HttpHost(host, port, getProtocol(old, scheme, host, port)); 32 } 33 34 40 protected Protocol getProtocol(HostConfiguration old, String scheme, String host, int port) 41 { 42 final Protocol oldProtocol = old.getProtocol(); 43 if (oldProtocol != null) { 44 final String oldScheme = oldProtocol.getScheme(); 45 if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) { 46 return oldProtocol; } 49 } 50 Protocol newProtocol = (scheme != null && scheme.toLowerCase().endsWith("s")) ? httpsProtocol 51 : httpProtocol; 52 if (newProtocol == null) { 53 newProtocol = Protocol.getProtocol(scheme); 54 } 55 return newProtocol; 56 } 57 58 } 59 | Popular Tags |