Top Description Inners Fields Constructors Methods
java.net

public abstract Class ProxySelector

extends Object
Class Inheritance
Known Direct Subclasses
java.net.ProxySelector.StaticProxySelector, sun.net.spi.DefaultProxySelector
Imports
java.io.IOException, java.util.List, sun.security.util.SecurityConstants

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 method. The currently registered proxy selector can be retrieved by calling getDefault method.

When a proxy selector is registered, for instance, a subclass of URLConnection class should call the select method for each URL request so that the proxy selector can decide if a direct, or proxied connection should be used. The select 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 method to notify the proxy selector that the proxy server is unavailable.

The default proxy selector does enforce a set of System Properties related to proxy settings.

Authors
Yingxian Wang, Jean-Christophe Collet
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static volatile ProxySelector
theProxySelector

The system wide proxy selector that selects the proxy server to use, if any, when connecting to a remote object referenced by an URL.

Constructor Summary

AccessConstructor and Description
public
ProxySelector()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
public abstract void
connectFailed(URI
The URI that the proxy at sa failed to serve.
uri
,
SocketAddress
The socket address of the proxy/SOCKS server
sa
,
IOException
The I/O exception thrown when the connect failed.
ioe
)

Called to indicate that a connection could not be established to a proxy/socks server.

public static ProxySelector

Returns:

the system-wide ProxySelector
getDefault
()

Gets the system-wide proxy selector.

public static ProxySelector

Returns:

a ProxySelector
of
(InetSocketAddress
The address of the proxy
proxyAddress
)

Returns a ProxySelector which uses the given proxy address for all HTTP and HTTPS requests.

public abstract List<Proxy>

Returns:

a List of Proxies. Each element in the List is of type Proxy; when no proxy is available, the list will contain one element of type Proxy that represents a direct connection.
select
(URI
The URI that a connection is required to
uri
)

Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at.

public static void
setDefault(ProxySelector
The HTTP proxy selector, or null to unset the proxy selector.
ps
)

Sets (or unsets) the system-wide proxy selector.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

theProxySelectorback to summary
private static volatile ProxySelector theProxySelector

The system wide proxy selector that selects the proxy server to use, if any, when connecting to a remote object referenced by an URL.

See Also
setDefault(ProxySelector)

Constructor Detail

ProxySelectorback to summary
public ProxySelector()

Constructor for subclasses to call.

Method Detail

connectFailedback to summary
public abstract void connectFailed(URI uri, SocketAddress sa, 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(URI), using the address and the IOException caught when trying to connect.

Parameters
uri:URI

The URI that the proxy at sa failed to serve.

sa:SocketAddress

The socket address of the proxy/SOCKS server

ioe:IOException

The I/O exception thrown when the connect failed.

Exceptions
IllegalArgumentException:
if either argument is null
getDefaultback to summary
public static ProxySelector getDefault()

Gets the system-wide proxy selector.

Returns:ProxySelector

the system-wide ProxySelector

Exceptions
SecurityException:
If a security manager has been installed and it denies NetPermission("getProxySelector")
Since
1.5
See Also
setDefault(ProxySelector)
ofback to summary
public static ProxySelector of(InetSocketAddress proxyAddress)

Returns a ProxySelector which uses the given proxy address for all HTTP and HTTPS requests. If proxyAddress is null then proxying is disabled.

Parameters
proxyAddress:InetSocketAddress

The address of the proxy

Returns:ProxySelector

a ProxySelector

Since
9
selectback to summary
public abstract List<Proxy> select(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 follows:

  • http URI for http connections
  • https URI for https connections
  • socket://host:port
    for tcp client sockets connections
Parameters
uri:URI

The URI that a connection is required to

Returns:List<Proxy>

a List of Proxies. Each element in the List is of type Proxy; when no proxy is available, the list will contain one element of type Proxy that represents a direct connection.

Exceptions
IllegalArgumentException:
if the argument is null or if the protocol or host cannot be determined from the provided uri
setDefaultback to summary
public static void setDefault(ProxySelector ps)

Sets (or unsets) the system-wide proxy selector.

Note

non-standard protocol handlers may ignore this setting.

Parameters
ps:ProxySelector

The HTTP proxy selector, or null to unset the proxy selector.

Exceptions
SecurityException:
If a security manager has been installed and it denies NetPermission("setProxySelector")
Since
1.5
See Also
getDefault()
java.net back to summary

pack-priv Class ProxySelector.StaticProxySelector

extends ProxySelector
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final List<Proxy>
private static final List<Proxy>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
connectFailed(URI
The URI that the proxy at sa failed to serve.
uri
,
SocketAddress
The socket address of the proxy/SOCKS server
sa
,
IOException
The I/O exception thrown when the connect failed.
e
)

Implements abstract java.net.ProxySelector.connectFailed.

Called to indicate that a connection could not be established to a proxy/socks server.

public List<Proxy>
select(URI
The URI that a connection is required to
uri
)

Implements abstract java.net.ProxySelector.select.

Selects all the applicable proxies based on the protocol to access the resource with and a destination address to access the resource at.

Inherited from java.net.ProxySelector:
getDefaultofsetDefault

Field Detail

listback to summary
pack-priv final List<Proxy> list
NO_PROXY_LISTback to summary
private static final List<Proxy> NO_PROXY_LIST

Constructor Detail

StaticProxySelectorback to summary
pack-priv StaticProxySelector(InetSocketAddress address)

Method Detail

connectFailedback to summary
public void connectFailed(URI uri, SocketAddress sa, IOException e)

Implements abstract java.net.ProxySelector.connectFailed.

Doc from java.net.ProxySelector.connectFailed.

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(URI), using the address and the IOException caught when trying to connect.

Parameters
uri:URI

The URI that the proxy at sa failed to serve.

sa:SocketAddress

The socket address of the proxy/SOCKS server

e:IOException

The I/O exception thrown when the connect failed.

Annotations
@Override
selectback to summary
public List<Proxy> select(URI uri)

Implements abstract java.net.ProxySelector.select.

Doc from java.net.ProxySelector.select.

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 follows:

  • http URI for http connections
  • https URI for https connections
  • socket://host:port
    for tcp client sockets connections
Parameters
uri:URI

The URI that a connection is required to

Returns:List<Proxy>

a List of Proxies. Each element in the List is of type Proxy; when no proxy is available, the list will contain one element of type Proxy that represents a direct connection.

Annotations
@Override