public abstract class

ProxySelector

extends Object
java.lang.Object
   ↳ java.net.ProxySelector

Class Overview

Selects an applicable proxy server when connecting to a resource specified by a URL. Proxy selectors are concrete subclasses of ProxySelector and can be set as default by calling the setDefault() method. If a connection can't be established, the caller should notify the proxy selector by invoking the connectFailed() method.

Summary

Public Constructors
ProxySelector()
Creates a new ProxySelector instance.
Public Methods
abstract void connectFailed(URI uri, SocketAddress sa, IOException ioe)
Notifies the ProxySelector that a connection to the proxy server could not be established.
static ProxySelector getDefault()
Gets the default ProxySelector of the system.
abstract List<Proxy> select(URI uri)
Gets all applicable proxies based on the accessing protocol of uri.
static void setDefault(ProxySelector selector)
Sets the default ProxySelector of the system.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ProxySelector ()

Since: API Level 1

Creates a new ProxySelector instance.

Public Methods

public abstract void connectFailed (URI uri, SocketAddress sa, IOException ioe)

Since: API Level 1

Notifies the ProxySelector that a connection to the proxy server could not be established. A concrete implementation should upon this notification maintain the list of available proxies, since an updated version should be provided by select().

Parameters
uri the URI to which the connection could not be established.
sa the address of the proxy.
ioe the exception which was thrown during connection establishment.
Throws
IllegalArgumentException if any argument is null.
See Also

public static ProxySelector getDefault ()

Since: API Level 1

Gets the default ProxySelector of the system.

Returns
  • the currently set default ProxySelector.
Throws
SecurityException if a security manager is installed but it doesn't have the NetPermission("getProxySelector").

public abstract List<Proxy> select (URI uri)

Since: API Level 1

Gets all applicable proxies based on the accessing protocol of uri. The format of URI is defined as below:

  • http URI stands for http connection.
  • https URI stands for https connection.
  • ftp URI stands for ftp connection.
  • socket:://ip:port URI stands for tcp client sockets connection.
  • Parameters
    uri the target URI object.
    Returns
    • a list containing all applicable proxies. If no proxy is available, the list contains only the Proxy.NO_PROXY element.
    Throws
    IllegalArgumentException if uri is null.

    public static void setDefault (ProxySelector selector)

    Since: API Level 1

    Sets the default ProxySelector of the system. Removes the system default ProxySelector if the parameter selector is set to null.

    Parameters
    selector the ProxySelector instance to set as default or null to remove the current default ProxySelector.
    Throws
    SecurityException if a security manager is installed but it doesn't have the NetPermission("setProxySelector").