ice.net.proxy
Class ProxyManager

java.lang.Object
  extended byice.net.proxy.ProxyManager
All Implemented Interfaces:
ProxyResolver

public class ProxyManager
extends Object
implements ProxyResolver

This class provides support for use of proxy servers. This class is used to initialize the proxy property of each HttpURLConnection, that is , control which proxies are used.

You must be aware that all the settings made in this class have the only effect to change the value of whatProxy().
As a consequence, you must study the order in which the whatProxy() method takes the settings into account to be sure to get the proper result.

For example, the method setProxyUse() disables all the proxies in all cases. So if you want to set a proxy server for a limited quantity of domains, sets the proxy use to true and sets the global proxy to null. Then, use the method setProxyDomain() for the specific domains.

Version:
1.6.0
Author:
Thomas Nøkleby, Jack van Ooststroom
See Also:
Proxy

Constructor Summary
ProxyManager()
          The hostname in property "http.proxyHost" is used as a global proxy at initialization.
 
Method Summary
 void addNonProxyDomain(String nonProxyDomain)
          Adds the specified nonProxyDomain to the list of non proxy domains of this ProxyManager.
 void addNonProxyDomainOrHost(String domainOrHost)
           
 void addNonProxyHost(String nonProxyHost)
          Adds the specified nonProxyHost to the list of non proxy hosts of this ProxyManager.
 void addNonProxyPort(int nonProxyPort)
          Adds the specified nonProxyPort to the list of non proxy ports of this ProxyManager.
 void clearNonProxyDomains()
          Clears the list of non proxy domains of this ProxyManager.
 void clearNonProxyHosts()
          Clears the list of non proxy hosts of this ProxyManager.
 void clearNonProxyPorts()
          Clears the list of non proxy ports of this ProxyManager.
 Enumeration elements()
          Returns an enumeration containing java.lang.String objects.
 Proxy[] findProxy(String url)
          Deprecated. As of 1.5.0, replaced by findProxyForUrl(URL).
 ConnectionRoute findProxyForUrl(URL url)
          Finds a usable connection route for the specified url.
 Proxy[] getAllGlobalProxies()
           
 Proxy[] getAllProxies()
          Returns an array containing all proxies used.
 String[] getAllProxyDomainsByProtocol(String protocol)
          Returns an array containing all domains used for the protocol specified.
 String[] getDomainsForProxy(Proxy p)
          Will return an array of strings giving all the domains the specified proxy will proxy.
 Proxy getGlobalProxy()
          Gets global proxy server.
 Proxy getGlobalProxy(String protocol)
          Gets global proxy server for a specified protocol.
 String[] getNonProxyDomains()
          Gets the list of non proxy domains of this ProxyManager.
 String[] getNonProxyHosts()
          Gets the list of non proxy hosts of this ProxyManager.
 int[] getNonProxyPorts()
          Gets the list of non proxy ports of this ProxyManager.
 String[] getNoProxy()
          Deprecated. As of 1.6.0, replaced by getNonProxyDomains() and getNonProxyHosts(). Please not that this method returned a list of both non proxy domains and hosts.
 Proxy getProxy(String domain)
          Returns the proxy set for a specific domain.
 Proxy getProxy(String host, int port)
           
 Proxy getProxy(String host, int port, String protocol)
           
 Proxy getProxyForDomain(String domain)
          Returns the http proxy for the specified domain, or null if none exists.
 Proxy getProxyForDomain(String domain, String protocol)
          Return the proxy for the specified domain and protocol, or null if none exists.
 boolean getProxyUse()
          Indicates if connections are going through proxies.
 boolean isNonProxyHost(String host)
          Checks to see if the specified host should not be proxied.
 boolean isNonProxyPort(int port)
          Checks to see if the specified port should not be proxied.
 boolean isNoProxy(String host)
          Deprecated. As of 1.6.0, replaced by isNonProxyHost(String).
 void readProxies(ObjectInput objectInput)
          Reads all proxies into this ProxyManager from the specified objectInput.
 void removeAllProxies()
          Removes all proxies.
 void removeGlobalProxy(Proxy proxyRef)
          Remove the global proxy server that correspond to the specified reference.
 void removeNonProxyDomain(String nonProxyDomain)
          Removes the specified nonProxyDomain from the list of non proxy domains of this ProxyManager.
 void removeNonProxyHost(String nonProxyHost)
          Removes the specified nonProxyHost from the list of non proxy hosts of this ProxyManager.
 void removeNonProxyPort(int nonProxyPort)
          Removes the specified nonProxyPort from the list of non proxy ports of this ProxyManager.
 void removeProxy(String domain)
          Removes a proxy server for a specific domain.
 void removeProxy(String domain, String protocol)
          Removes a proxy server for a specific domain and a specific protocol.
 void rereadProperties()
           
 void setGlobalProxy(Proxy proxy)
          Sets the global proxy server.
 void setNonProxyDomains(String[] nonProxyDomains)
          Sets the list of non proxy domains of this ProxyManager to the specified nonProxyDomains.
 void setNonProxyHosts(String nonProxyHosts)
          Sets the list of non proxy hosts of this ProxyManager to the specified nonProxyHosts.
 void setNonProxyHosts(String[] nonProxyHosts)
          Sets the list of non proxy hosts of this ProxyManager to the specified nonProxyHosts.
 void setNonProxyPorts(int[] nonProxyPorts)
          Sets the list of non proxy ports of this ProxyManager to the specified nonProxyPorts.
 void setNonProxyPorts(String nonProxyPorts)
          Sets the list of non proxy ports of this ProxyManager to the specified nonProxyPorts.
 void setNoProxy(String domainOrHost)
          Deprecated. As of 1.6.0, replaced by addNonProxyDomainOrHost(String).
 void setNoProxy(String[] domains)
          Deprecated. As of 1.6.0, replaced by setNonProxyHosts(String[]). Please note that this method was used to set the non proxy hosts list, not the non proxy domain list.
 void setProxyDomain(String domain, Proxy proxy)
          Sets a proxy server for a specific domain.
 void setProxyForDomain(String domain, Proxy proxy)
          Set the proxy for the specified domain and protocol.
 void setProxyUse(boolean useproxies)
          Set the use of proxies.
 Proxy whatProxy(String host)
          Deprecated. As of 1.6.0, replaced by getProxy(String, int).
 Proxy whatProxy(String host, String protocol)
          Deprecated. As of 1.6.0, replaced by getProxy(String, int, String).
 void writeProxies(ObjectOutput objectOutput)
          Writes all proxies contained in this ProxyManager to the specified objectOutput.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyManager

public ProxyManager()
The hostname in property "http.proxyHost" is used as a global proxy at initialization. If this propery is not set, the manager assumes that no proxies are to be used.

See Also:
setProxyUse(boolean)
Method Detail

addNonProxyDomainOrHost

public void addNonProxyDomainOrHost(String domainOrHost)
Parameters:
domainOrHost -
Since:
1.6.0

addNonProxyDomain

public void addNonProxyDomain(String nonProxyDomain)

Adds the specified nonProxyDomain to the list of non proxy domains of this ProxyManager.

Parameters:
nonProxyDomain - the non proxy domain to be added.
Since:
1.6.0
See Also:
clearNonProxyDomains(), getNonProxyDomains(), removeNonProxyDomain(String), setNonProxyDomains(String[]), addNonProxyHost(String), addNonProxyPort(int)

addNonProxyHost

public void addNonProxyHost(String nonProxyHost)

Adds the specified nonProxyHost to the list of non proxy hosts of this ProxyManager.

Parameters:
nonProxyHost - the non proxy host to be added.
Since:
1.6.0
See Also:
clearNonProxyHosts(), getNonProxyHosts(), removeNonProxyHost(String), setNonProxyHosts(String[]), addNonProxyDomain(String), addNonProxyPort(int)

addNonProxyPort

public void addNonProxyPort(int nonProxyPort)

Adds the specified nonProxyPort to the list of non proxy ports of this ProxyManager.

Parameters:
nonProxyPort - the non proxy port to be added.
Since:
1.6.0
See Also:
clearNonProxyPorts(), getNonProxyPorts(), removeNonProxyPort(int), setNonProxyPorts(int[]), addNonProxyDomain(String), addNonProxyHost(String)

clearNonProxyDomains

public void clearNonProxyDomains()

Clears the list of non proxy domains of this ProxyManager.

Since:
1.6.0
See Also:
addNonProxyDomain(String), getNonProxyDomains(), removeNonProxyDomain(String), setNonProxyDomains(String[]), clearNonProxyHosts(), clearNonProxyPorts()

clearNonProxyHosts

public void clearNonProxyHosts()

Clears the list of non proxy hosts of this ProxyManager.

Since:
1.6.0
See Also:
addNonProxyHost(String), getNonProxyHosts(), removeNonProxyHost(String), setNonProxyHosts(String[]), clearNonProxyDomains(), clearNonProxyPorts()

clearNonProxyPorts

public void clearNonProxyPorts()

Clears the list of non proxy ports of this ProxyManager.

Since:
1.6.0
See Also:
addNonProxyPort(int), getNonProxyPorts(), removeNonProxyPort(int), setNonProxyPorts(int[]), clearNonProxyDomains(), clearNonProxyHosts()

findProxyForUrl

public ConnectionRoute findProxyForUrl(URL url)
Description copied from interface: ProxyResolver

Finds a usable connection route for the specified url.

Specified by:
findProxyForUrl in interface ProxyResolver
Parameters:
url - the full URL being accessed.
Returns:
a usable ConnectionRoute.

getNonProxyDomains

public String[] getNonProxyDomains()

Gets the list of non proxy domains of this ProxyManager.

Returns:
the list of non proxy domains.
Since:
1.6.0
See Also:
addNonProxyDomain(String), clearNonProxyDomains(), removeNonProxyDomain(String), setNonProxyDomains(String[]), getNonProxyHosts(), getNonProxyPorts()

getNonProxyHosts

public String[] getNonProxyHosts()

Gets the list of non proxy hosts of this ProxyManager.

Returns:
the list of non proxy hosts.
Since:
1.6.0
See Also:
addNonProxyHost(String), clearNonProxyHosts(), removeNonProxyHost(String), setNonProxyHosts(String[]), getNonProxyDomains(), getNonProxyPorts()

getNonProxyPorts

public int[] getNonProxyPorts()

Gets the list of non proxy ports of this ProxyManager.

Returns:
the list of non proxy ports.
Since:
1.6.0
See Also:
addNonProxyPort(int), clearNonProxyPorts(), removeNonProxyPort(int), setNonProxyPorts(int[]), getNonProxyDomains(), getNonProxyHosts()

getProxy

public Proxy getProxy(String host,
                      int port)
Parameters:
host -
port -
Returns:
Since:
1.6.0
See Also:
getProxy(String, int, String)

getProxy

public Proxy getProxy(String host,
                      int port,
                      String protocol)
Parameters:
host -
port -
protocol -
Returns:
Since:
1.6.0

isNonProxyHost

public boolean isNonProxyHost(String host)

Checks to see if the specified host should not be proxied.

Parameters:
host -
Returns:
true if the specified host should not be proxied, false if not.
Since:
1.6.0
See Also:
isNonProxyPort(int)

isNonProxyPort

public boolean isNonProxyPort(int port)

Checks to see if the specified port should not be proxied.

Parameters:
port -
Returns:
true if the specified port should not be proxied, false if not.
Since:
1.6.0
See Also:
isNonProxyHost(String)

readProxies

public void readProxies(ObjectInput objectInput)

Reads all proxies into this ProxyManager from the specified objectInput. That is, all proxies and global proxies, and all non proxy hosts, domains, and ports.

Parameters:
objectInput - the object input to read from.
See Also:
writeProxies(ObjectOutput)

removeNonProxyDomain

public void removeNonProxyDomain(String nonProxyDomain)

Removes the specified nonProxyDomain from the list of non proxy domains of this ProxyManager.

Parameters:
nonProxyDomain - the non proxy domain to be removed.
Since:
1.6.0
See Also:
addNonProxyDomain(String), clearNonProxyDomains(), getNonProxyDomains(), setNonProxyDomains(String[]), removeNonProxyHost(String), removeNonProxyPort(int)

removeNonProxyHost

public void removeNonProxyHost(String nonProxyHost)

Removes the specified nonProxyHost from the list of non proxy hosts of this ProxyManager.

Parameters:
nonProxyHost - the non proxy host to be removed.
Since:
1.6.0
See Also:
addNonProxyHost(String), clearNonProxyHosts(), getNonProxyHosts(), setNonProxyHosts(String[]), removeNonProxyDomain(String), removeNonProxyPort(int)

removeNonProxyPort

public void removeNonProxyPort(int nonProxyPort)

Removes the specified nonProxyPort from the list of non proxy ports of this ProxyManager.

Parameters:
nonProxyPort - the non proxy port to be removed.
Since:
1.6.0
See Also:
addNonProxyPort(int), clearNonProxyPorts(), getNonProxyPorts(), setNonProxyPorts(int[]), removeNonProxyDomain(String), removeNonProxyHost(String)

setNonProxyDomains

public void setNonProxyDomains(String[] nonProxyDomains)

Sets the list of non proxy domains of this ProxyManager to the specified nonProxyDomains. Please note that any previous set non proxy domain(s) will be overriden.

Parameters:
nonProxyDomains - the new proxy domains.
Since:
1.6.0
See Also:
addNonProxyDomain(String), clearNonProxyDomains(), getNonProxyDomains(), removeNonProxyDomain(String), setNonProxyHosts(String[]), setNonProxyPorts(int[])

setNonProxyHosts

public void setNonProxyHosts(String nonProxyHosts)

Sets the list of non proxy hosts of this ProxyManager to the specified nonProxyHosts. Please note that any previous set non proxy host(s) will be overriden.

Parameters:
nonProxyHosts - the new non proxy hosts.
Since:
1.6.0

setNonProxyHosts

public void setNonProxyHosts(String[] nonProxyHosts)

Sets the list of non proxy hosts of this ProxyManager to the specified nonProxyHosts. Please note that any previous set non proxy host(s) will be overriden.

Parameters:
nonProxyHosts - the new non proxy hosts.
Since:
1.6.0
See Also:
addNonProxyHost(String), clearNonProxyHosts(), getNonProxyHosts(), removeNonProxyHost(String), setNonProxyDomains(String[]), setNonProxyPorts(int[])

setNonProxyPorts

public void setNonProxyPorts(String nonProxyPorts)

Sets the list of non proxy ports of this ProxyManager to the specified nonProxyPorts. Please note that any previous set non proxy port(s) will be overriden.

Parameters:
nonProxyPorts - the new non proxy ports.
Since:
1.6.0

setNonProxyPorts

public void setNonProxyPorts(int[] nonProxyPorts)

Sets the list of non proxy ports of this ProxyManager to the specified nonProxyPorts. Please note that any previous set non proxy port(s) will be overriden.

Parameters:
nonProxyPorts - the new non proxy ports.
Since:
1.6.0
See Also:
addNonProxyPort(int), clearNonProxyPorts(), getNonProxyPorts(), removeNonProxyPort(int), setNonProxyDomains(String[]), setNonProxyHosts(String[])

writeProxies

public void writeProxies(ObjectOutput objectOutput)

Writes all proxies contained in this ProxyManager to the specified objectOutput. That is, all proxies and global proxies, and all non proxy hosts, domains, and ports.

Parameters:
objectOutput - the object output to write to.
See Also:
readProxies(ObjectInput)

findProxy

public Proxy[] findProxy(String url)
Deprecated. As of 1.5.0, replaced by findProxyForUrl(URL).

Specified by:
findProxy in interface ProxyResolver

getNoProxy

public String[] getNoProxy()
Deprecated. As of 1.6.0, replaced by getNonProxyDomains() and getNonProxyHosts(). Please not that this method returned a list of both non proxy domains and hosts.

See Also:
getNonProxyPorts()

isNoProxy

public boolean isNoProxy(String host)
Deprecated. As of 1.6.0, replaced by isNonProxyHost(String).

See Also:
isNonProxyPort(int)

setNoProxy

public void setNoProxy(String domainOrHost)
Deprecated. As of 1.6.0, replaced by addNonProxyDomainOrHost(String).

See Also:
addNonProxyDomain(String), addNonProxyHost(String), addNonProxyPort(int)

setNoProxy

public void setNoProxy(String[] domains)
Deprecated. As of 1.6.0, replaced by setNonProxyHosts(String[]). Please note that this method was used to set the non proxy hosts list, not the non proxy domain list.

See Also:
setNonProxyDomains(String[]), setNonProxyPorts(int[])

whatProxy

public Proxy whatProxy(String host)
Deprecated. As of 1.6.0, replaced by getProxy(String, int).


whatProxy

public Proxy whatProxy(String host,
                       String protocol)
Deprecated. As of 1.6.0, replaced by getProxy(String, int, String).


rereadProperties

public void rereadProperties()

getProxyUse

public boolean getProxyUse()
Indicates if connections are going through proxies. This method allows to disable and unable the use of all proxies. But it does not guarantee that a proxy server will be used. To know if a proxy server will be used for a specific domain, use the method whatProxy.

See Also:
setGlobalProxy(Proxy), whatProxy(String)

setProxyUse

public void setProxyUse(boolean useproxies)
Set the use of proxies.

Parameters:
useproxies - if true, all http connections will use proxies.
See Also:
getProxyUse(), setGlobalProxy(Proxy), whatProxy(String)

removeAllProxies

public void removeAllProxies()
Removes all proxies. No-Proxy information is retained, however.


setGlobalProxy

public void setGlobalProxy(Proxy proxy)
Sets the global proxy server. The proxy host and port are initialized with the values of the system properties:
 http.proxyHost
 http.proxyPort

Parameters:
proxy - The global proxy server.
See Also:
getProxyUse(), getGlobalProxy(), whatProxy(String)

getGlobalProxy

public Proxy getGlobalProxy()
Gets global proxy server.

Returns:
The proxy server.
See Also:
getProxyUse(), setGlobalProxy(Proxy), whatProxy(String)

getGlobalProxy

public Proxy getGlobalProxy(String protocol)
Gets global proxy server for a specified protocol.

Returns:
The proxy server.
See Also:
getProxyUse(), setGlobalProxy(Proxy), whatProxy(String)

getAllGlobalProxies

public Proxy[] getAllGlobalProxies()

setProxyDomain

public void setProxyDomain(String domain,
                           Proxy proxy)
Sets a proxy server for a specific domain. If a specific proxy is already defined for the domain, then it is replaced.

Parameters:
domain - the domain for which the proxy will be set
proxy - the proxy server
See Also:
getProxyUse(), removeProxy(String), whatProxy(String)

removeProxy

public void removeProxy(String domain)
Removes a proxy server for a specific domain.

Note: this method does not disable the use of proxies for a specific domain. It disables the use of a specific proxy for a domain. Use the setNoProxy() method if you want to disable proxies for a domain.

Parameters:
domain - the domain for which the specific proxy will be removed.
See Also:
getProxyUse(), whatProxy(String)

removeProxy

public void removeProxy(String domain,
                        String protocol)
Removes a proxy server for a specific domain and a specific protocol.

Note: this method does not disable the use of proxies for a specific domain. It disables the use of a specific proxy for a domain. Use the setNoProxy() method if you want to disable proxies for a domain.

Parameters:
domain - the domain for which the specific proxy will be removed.
protocol - the protocol for which the specific proxy will be removed.
See Also:
getProxyUse(), whatProxy(String)

removeGlobalProxy

public void removeGlobalProxy(Proxy proxyRef)
Remove the global proxy server that correspond to the specified reference.


getProxy

public Proxy getProxy(String domain)
Returns the proxy set for a specific domain. If no specific proxy is set for the given domain, the method simply returns null.

See Also:
getProxyUse(), removeProxy(String), whatProxy(String)

getDomainsForProxy

public String[] getDomainsForProxy(Proxy p)
Will return an array of strings giving all the domains the specified proxy will proxy.


getProxyForDomain

public Proxy getProxyForDomain(String domain,
                               String protocol)
Return the proxy for the specified domain and protocol, or null if none exists.


getProxyForDomain

public Proxy getProxyForDomain(String domain)
Returns the http proxy for the specified domain, or null if none exists.


setProxyForDomain

public void setProxyForDomain(String domain,
                              Proxy proxy)
Set the proxy for the specified domain and protocol.


getAllProxies

public Proxy[] getAllProxies()
Returns an array containing all proxies used. If no proxies are present, it returns null.


getAllProxyDomainsByProtocol

public String[] getAllProxyDomainsByProtocol(String protocol)
Returns an array containing all domains used for the protocol specified. If no proxies are present, it returns null.


elements

public Enumeration elements()
Returns an enumeration containing java.lang.String objects. Each represent a domain/protocol pair.