APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.net.spi

public Class DefaultProxySelector

extends ProxySelector
Class Inheritance
Imports
java.net.InetSocketAddress, .Proxy, .ProxySelector, .SocketAddress, .URI, java.util.Collections, .List, .Locale, .StringJoiner, java.io.IOException, java.util.regex.Pattern, java.util.stream.Stream, sun.net.NetProperties, .SocksProxy

Supports proxy settings using system properties This proxy selector provides backward compatibility with the old http protocol handler as far as how proxy is set Most of the implementation copied from the old http protocol handler Supports http/https/ftp.proxyHost, http/https/ftp.proxyPort, proxyHost, proxyPort, and http/https/ftp.nonProxyHost, and socks.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
DefaultProxySelector.NonProxyInfo

How to deal with "non proxy hosts": since we do have to generate a pattern we don't want to do that if it's not necessary.

Field Summary

Modifier and TypeField and Description
private static boolean
private static final List<Proxy>
pack-priv static final String[][]
props

This is where we define all the valid System Properties we have to support for each given protocol.

private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
connectFailed(URI uri, SocketAddress sa, IOException ioe)

Implements abstract java.net.ProxySelector.connectFailed.

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

private int
defaultPort(String protocol)

private Proxy[]
determineProxies(final String urlhost, final String protocol, final DefaultProxySelector.NonProxyInfo nonProxyInfo)

pack-priv static String
disjunctToRegex(String
non-null mask disjunct
disjunct
)

Returns: java regex string corresponding to this mask

private synchronized native Proxy[]
getSystemProxies(String protocol, String host)

private static native boolean
init()

public List<Proxy>
select(URI uri)

Implements abstract java.net.ProxySelector.select.

select() method.

pack-priv static boolean
shouldNotUseProxyFor(Pattern pattern, String urlhost)

Returns: true if given this pattern for non-proxy hosts and this urlhost the proxy should NOT be used to access this urlhost

public static int
pack-priv static Pattern
toPattern(String
non-null mask
mask
)

Returns: java.util.regex.Pattern corresponding to this mask or null in case mask should not match anything

Inherited from java.net.ProxySelector:
getDefaultofsetDefault

Field Detail

hasSystemProxiesback to summary
private static boolean hasSystemProxies
NO_PROXY_LISTback to summary
private static final List<Proxy> NO_PROXY_LIST
propsback to summary
pack-priv static final String[][] props

This is where we define all the valid System Properties we have to support for each given protocol. The format of this 2 dimensional array is : - 1 row per protocol (http, ftp, ...) - 1st element of each row is the protocol name - subsequent elements are prefixes for Host & Port properties listed in order of priority. Example: {"ftp", "ftp.proxy", "ftpProxy", "proxy", "socksProxy"}, means for FTP we try in that order: + ftp.proxyHost & ftp.proxyPort + ftpProxyHost & ftpProxyPort + proxyHost & proxyPort + socksProxyHost & socksProxyPort Note that the socksProxy should *always* be the last on the list

SOCKS_PROXY_VERSIONback to summary
private static final String SOCKS_PROXY_VERSION

Constructor Detail

DefaultProxySelectorback to summary
public DefaultProxySelector()

Method Detail

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

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.

defaultPortback to summary
private int defaultPort(String protocol)
determineProxiesback to summary
private Proxy[] determineProxies(final String urlhost, final String protocol, final DefaultProxySelector.NonProxyInfo nonProxyInfo)
disjunctToRegexback to summary
pack-priv static String disjunctToRegex(String disjunct)
Parameters
disjunct:String

non-null mask disjunct

Returns:String

java regex string corresponding to this mask

getSystemProxiesback to summary
private synchronized native Proxy[] getSystemProxies(String protocol, String host)
initback to summary
private static native boolean init()
selectback to summary
public List<Proxy> select(URI uri)

Implements abstract java.net.ProxySelector.select.

select() method. Where all the hard work is done. Build a list of proxies depending on URI. Since we're only providing compatibility with the system properties from previous releases (see list above), that list will typically contain one single proxy, default being NO_PROXY. If we can get a system proxy it might contain more entries.

shouldNotUseProxyForback to summary
pack-priv static boolean shouldNotUseProxyFor(Pattern pattern, String urlhost)
Returns:boolean

true if given this pattern for non-proxy hosts and this urlhost the proxy should NOT be used to access this urlhost

socksProxyVersionback to summary
public static int socksProxyVersion()
toPatternback to summary
pack-priv static Pattern toPattern(String mask)
Parameters
mask:String

non-null mask

Returns:Pattern

java.util.regex.Pattern corresponding to this mask or null in case mask should not match anything

sun.net.spi back to summary

pack-priv Class DefaultProxySelector.NonProxyInfo

extends Object
Class Inheritance

How to deal with "non proxy hosts": since we do have to generate a pattern we don't want to do that if it's not necessary. Therefore we do cache the result, on a per-protocol basis, and change it only when the "source", i.e. the system property, did change.

Field Summary

Modifier and TypeField and Description
pack-priv final String
pack-priv static final String
pack-priv static DefaultProxySelector.NonProxyInfo
pack-priv String
pack-priv static DefaultProxySelector.NonProxyInfo
pack-priv Pattern
pack-priv final String
pack-priv static DefaultProxySelector.NonProxyInfo

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultValback to summary
pack-priv final String defaultVal
defStringValback to summary
pack-priv static final String defStringVal
ftpNonProxyInfoback to summary
pack-priv static DefaultProxySelector.NonProxyInfo ftpNonProxyInfo
hostsSourceback to summary
pack-priv String hostsSource
httpNonProxyInfoback to summary
pack-priv static DefaultProxySelector.NonProxyInfo httpNonProxyInfo
patternback to summary
pack-priv Pattern pattern
propertyback to summary
pack-priv final String property
socksNonProxyInfoback to summary
pack-priv static DefaultProxySelector.NonProxyInfo socksNonProxyInfo

Constructor Detail

NonProxyInfoback to summary
pack-priv NonProxyInfo(String p, String s, Pattern pattern, String d)