java.net
Class ProxySelector

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.net.ProxySelector

public abstract class ProxySelector
extends Object sample code for java.lang.Object definition code for java.lang.Object

Selects the proxy server to use, if any, when connecting to the network resource referenced by a URL. A proxy selector is a concrete sub-class of this class and is registered by invoking the setDefault sample code for java.net.ProxySelector.setDefault(java.net.ProxySelector) definition code for java.net.ProxySelector.setDefault(java.net.ProxySelector) method. The currently registered proxy selector can be retrieved by calling getDefault sample code for java.net.ProxySelector.getDefault() definition code for java.net.ProxySelector.getDefault() method.

When a proxy selector is registered, for instance, a subclass of URLConnection class should call the select sample code for java.net.ProxySelector.select(java.net.URI) definition code for java.net.ProxySelector.select(java.net.URI) method for each URL request so that the proxy selector can decide if a direct, or proxied connection should be used. The select sample code for java.net.ProxySelector.select(java.net.URI) definition code for java.net.ProxySelector.select(java.net.URI) method returns an iterator over a collection with the preferred connection approach.

If a connection cannot be established to a proxy (PROXY or SOCKS) servers then the caller should call the proxy selector's connectFailed sample code for java.net.ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException) definition code for java.net.ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException) method to notify the proxy selector that the proxy server is unavailable.

Since:
1.5

Constructor Summary
ProxySelector sample code for java.net.ProxySelector.ProxySelector() definition code for java.net.ProxySelector.ProxySelector() ()
           
 
Method Summary
abstract  void connectFailed sample code for java.net.ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException) definition code for java.net.ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException) (URI sample code for java.net.URI definition code for java.net.URI  uri, SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  sa, IOException sample code for java.io.IOException definition code for java.io.IOException  ioe)
          Called to indicate that a connection could not be established to a proxy/socks server.
static ProxySelector sample code for java.net.ProxySelector definition code for java.net.ProxySelector getDefault sample code for java.net.ProxySelector.getDefault() definition code for java.net.ProxySelector.getDefault() ()
          Gets the system-wide proxy selector.
abstract  List sample code for java.util.List definition code for java.util.List <Proxy sample code for java.net.Proxy definition code for java.net.Proxy > select sample code for java.net.ProxySelector.select(java.net.URI) definition code for java.net.ProxySelector.select(java.net.URI) (URI sample code for java.net.URI definition code for java.net.URI  uri)
          Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at.
static void setDefault sample code for java.net.ProxySelector.setDefault(java.net.ProxySelector) definition code for java.net.ProxySelector.setDefault(java.net.ProxySelector) (ProxySelector sample code for java.net.ProxySelector definition code for java.net.ProxySelector  ps)
          Sets (or unsets) the system-wide proxy selector.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

ProxySelector sample code for java.net.ProxySelector() definition code for java.net.ProxySelector()

public ProxySelector()
Method Detail

getDefault sample code for java.net.ProxySelector.getDefault() definition code for java.net.ProxySelector.getDefault()

public static ProxySelector sample code for java.net.ProxySelector definition code for java.net.ProxySelector  getDefault()
Gets the system-wide proxy selector.

Returns:
the system-wide ProxySelector
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - If a security manager has been installed and it denies NetPermission sample code for java.net.NetPermission definition code for java.net.NetPermission ("getProxySelector")
Since:
1.5
See Also:
setDefault(ProxySelector) sample code for java.net.ProxySelector.setDefault(java.net.ProxySelector) definition code for java.net.ProxySelector.setDefault(java.net.ProxySelector)

setDefault sample code for java.net.ProxySelector.setDefault(java.net.ProxySelector) definition code for java.net.ProxySelector.setDefault(java.net.ProxySelector)

public static void setDefault(ProxySelector sample code for java.net.ProxySelector definition code for java.net.ProxySelector  ps)
Sets (or unsets) the system-wide proxy selector. Note: non-standard procotol handlers may ignore this setting.

Parameters:
ps - The HTTP proxy selector, or null to unset the proxy selector.
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - If a security manager has been installed and it denies NetPermission sample code for java.net.NetPermission definition code for java.net.NetPermission ("setProxySelector")
Since:
1.5
See Also:
getDefault() sample code for java.net.ProxySelector.getDefault() definition code for java.net.ProxySelector.getDefault()

select sample code for java.net.ProxySelector.select(java.net.URI) definition code for java.net.ProxySelector.select(java.net.URI)

public abstract List sample code for java.util.List definition code for java.util.List <Proxy sample code for java.net.Proxy definition code for java.net.Proxy > select(URI sample code for java.net.URI definition code for java.net.URI  uri)
Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at. The format of the URI is defined as follow:

Parameters:
uri - The URI that a connection is required to
Returns:
a List of Proxies. Each element in the the List is of type Proxy sample code for java.net.Proxy definition code for java.net.Proxy ; when no proxy is available, the list will contain one element of type Proxy sample code for java.net.Proxy definition code for java.net.Proxy that represents a direct connection.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if either argument is null

connectFailed sample code for java.net.ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException) definition code for java.net.ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException)

public abstract void connectFailed(URI sample code for java.net.URI definition code for java.net.URI  uri,
                                   SocketAddress sample code for java.net.SocketAddress definition code for java.net.SocketAddress  sa,
                                   IOException sample code for java.io.IOException definition code for java.io.IOException  ioe)
Called to indicate that a connection could not be established to a proxy/socks server. An implementation of this method can temporarily remove the proxies or reorder the sequence of proxies returned by select(String, String), using the address and they kind of IOException given.

Parameters:
uri - The URI that the proxy at sa failed to serve.
sa - The socket address of the proxy/SOCKS server
ioe - The I/O exception thrown when the connect failed.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if either argument is null