Class ProxySelector
- java.lang.Object
-
- java.net.ProxySelector
-
public abstract class ProxySelector extends Object
Selects the proxy server to use, if any, when connecting to a given URL.System Properties
The default proxy selector is configured by system properties.
Hostname patterns URL scheme property name description default ftp ftp.nonProxyHosts Hostname pattern for FTP servers to connect to directly (without a proxy). http http.nonProxyHosts Hostname pattern for HTTP servers to connect to directly (without a proxy). https https.nonProxyHosts Hostname pattern for HTTPS servers to connect to directly (without a proxy). HTTP Proxies URL scheme property name description default ftp ftp.proxyHost Hostname of the HTTP proxy server used for FTP requests. ftp.proxyPort Port number of the HTTP proxy server used for FTP requests. 80 http http.proxyHost Hostname of the HTTP proxy server used for HTTP requests. http.proxyPort Port number of the HTTP proxy server used for HTTP requests. 80 https https.proxyHost Hostname of the HTTP proxy server used for HTTPS requests. https.proxyPort Port number of the HTTP proxy server used for HTTPS requests. 443 ftp, http or https proxyHost Hostname of the HTTP proxy server used for FTP, HTTP and HTTPS requests. proxyPort Port number of the HTTP proxy server. 80 for FTP and HTTP
443 for HTTPSSOCKS Proxies URL scheme property name description default ftp, http, https or socket socksProxyHost Hostname of the SOCKS proxy server used for FTP, HTTP, HTTPS and raw sockets.
Raw socket URLs are of the formsocket://host:portsocksProxyPort Port number of the SOCKS proxy server. 1080 Hostname patterns specify which hosts should be connected to directly, ignoring any other proxy system properties. If the URL's host matches the corresponding hostname pattern,
Proxy.NO_PROXYis returned.The format of a hostname pattern is a list of hostnames that are separated by
|and that use*as a wildcard. For example, setting thehttp.nonProxyHostsproperty to*.android.com|*.kernel.orgwill cause requests tohttp://developer.android.comto be made without a proxy.The default proxy selector always returns exactly one proxy. If no proxy is applicable,
Proxy.NO_PROXYis returned. If multiple proxies are applicable, such as when both theproxyHostandsocksProxyHostsystem properties are set, the result is the property listed earliest in the table above.Alternatives
To request a URL without involving the system proxy selector, explicitly specify a proxy or
Proxy.NO_PROXYusingURL.openConnection(Proxy).Use
setDefault(ProxySelector)to install a custom proxy selector.
-
-
Constructor Summary
Constructors Constructor Description ProxySelector()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidconnectFailed(URI uri, SocketAddress address, IOException failure)Notifies thisProxySelectorthat a connection to the proxy server could not be established.static ProxySelectorgetDefault()Returns the default proxy selector, or null if none exists.abstract List<Proxy>select(URI uri)Returns the proxy servers to use on connections touri.static voidsetDefault(ProxySelector selector)Sets the default proxy selector.
-
-
-
Method Detail
-
getDefault
public static ProxySelector getDefault()
Returns the default proxy selector, or null if none exists.
-
setDefault
public static void setDefault(ProxySelector selector)
Sets the default proxy selector. Ifselectoris null, the current proxy selector will be removed.
-
select
public abstract List<Proxy> select(URI uri)
Returns the proxy servers to use on connections touri. This list will containProxy.NO_PROXYif no proxy server should be used.- Throws:
IllegalArgumentException- ifuriis null.
-
connectFailed
public abstract void connectFailed(URI uri, SocketAddress address, IOException failure)
Notifies thisProxySelectorthat a connection to the proxy server could not be established.- Parameters:
uri- the URI to which the connection could not be established.address- the address of the proxy.failure- the exception which was thrown during connection establishment.- Throws:
IllegalArgumentException- if any argument is null.
-
-