KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > contrib > ssl > HostConfigurationWithHostFactory


1 package org.apache.commons.httpclient.contrib.ssl;
2
3 import org.apache.commons.httpclient.HostConfiguration;
4 import org.apache.commons.httpclient.HttpURL;
5 import org.apache.commons.httpclient.protocol.Protocol;
6
7 /**
8  * A kind of HostConfiguration that gets its Host from a factory. This is useful
9  * for integrating a specialized Protocol or SocketFactory; for example, a
10  * SecureSocketFactory that authenticates via SSL. Use
11  * HttpClient.setHostConfiguration to install a HostConfigurationWithHostFactory
12  * that contains the specialized HostFactory, Protocol or SocketFactory.
13  * <p>
14  * An alternative is to use Protocol.registerProtocol to register a specialized
15  * Protocol. But that has drawbacks: it makes it hard to integrate modules (e.g.
16  * web applications in a servlet container) with different strategies, because
17  * they share the specialized Protocol (Protocol.PROTOCOLS is static). And it
18  * can't support different Protocols for different hosts or ports (since the
19  * host and port aren't parameters to Protocol.getProtocol).
20  *
21  * @author John Kristian
22  */

23 class HostConfigurationWithHostFactory extends HostConfiguration
24 {
25     public HostConfigurationWithHostFactory(HttpHostFactory factory)
26     {
27         this.factory = factory;
28     }
29
30     private HostConfigurationWithHostFactory(HostConfigurationWithHostFactory that)
31     {
32         super(that);
33         this.factory = that.factory;
34     }
35
36     private final HttpHostFactory factory;
37
38     public Object JavaDoc clone()
39     {
40         return new HostConfigurationWithHostFactory(this);
41     }
42
43     private static final String JavaDoc DEFAULT_SCHEME = new String JavaDoc(HttpURL.DEFAULT_SCHEME);
44
45     public void setHost(String JavaDoc host)
46     {
47         setHost(host, Protocol.getProtocol(DEFAULT_SCHEME).getDefaultPort());
48     }
49
50     public void setHost(final String JavaDoc host, int port)
51     {
52         setHost(host, port, DEFAULT_SCHEME);
53     }
54
55     public synchronized void setHost(String JavaDoc host, int port, String JavaDoc scheme)
56     {
57         setHost(factory.getHost(this, scheme, host, port));
58     }
59
60 }
61
Popular Tags