Class PacProxySelector
- java.lang.Object
-
- java.net.ProxySelector
-
- com.github.markusbernhardt.proxy.selector.pac.PacProxySelector
-
public class PacProxySelector extends java.net.ProxySelector
ProxySelector that will use a PAC script to find an proxy for a given URI.
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
enabled
private static java.lang.String
PAC_DIRECT
private static java.lang.String
PAC_SOCKS
private PacScriptParser
pacScriptParser
-
Constructor Summary
Constructors Constructor Description PacProxySelector(PacScriptSource pacSource)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.net.Proxy
buildProxyFromPacResult(java.lang.String pacResult)
The proxy evaluator will return a proxy string.private static java.lang.String
concat(java.lang.String[] strings, int startIndex)
void
connectFailed(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe)
connectFailedprivate java.util.List<java.net.Proxy>
findProxy(java.net.URI uri)
Evaluation of the given URL with the PAC-file.static boolean
isEnabled()
Checks if the selector is currently enabled.java.util.List<java.net.Proxy>
select(java.net.URI uri)
selectprivate void
selectEngine(PacScriptSource pacSource)
Selects one of the available PAC parser engines.static void
setEnabled(boolean enable)
Can be used to enable / disable the proxy selector.
-
-
-
Field Detail
-
PAC_SOCKS
private static final java.lang.String PAC_SOCKS
- See Also:
- Constant Field Values
-
PAC_DIRECT
private static final java.lang.String PAC_DIRECT
- See Also:
- Constant Field Values
-
pacScriptParser
private PacScriptParser pacScriptParser
-
enabled
private static volatile boolean enabled
-
-
Constructor Detail
-
PacProxySelector
public PacProxySelector(PacScriptSource pacSource)
Constructor- Parameters:
pacSource
- the source for the PAC file.
-
-
Method Detail
-
setEnabled
public static void setEnabled(boolean enable)
Can be used to enable / disable the proxy selector. If disabled it will return DIRECT for all urls.- Parameters:
enable
- the new status to set.
-
isEnabled
public static boolean isEnabled()
Checks if the selector is currently enabled.- Returns:
- true if enabled else false.
-
selectEngine
private void selectEngine(PacScriptSource pacSource)
Selects one of the available PAC parser engines.- Parameters:
pacSource
- to use as input.
-
connectFailed
public void connectFailed(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe)
connectFailed- Specified by:
connectFailed
in classjava.net.ProxySelector
- See Also:
ProxySelector.connectFailed(java.net.URI, java.net.SocketAddress, java.io.IOException)
-
select
public java.util.List<java.net.Proxy> select(java.net.URI uri)
select- Specified by:
select
in classjava.net.ProxySelector
- See Also:
ProxySelector.select(java.net.URI)
-
findProxy
private java.util.List<java.net.Proxy> findProxy(java.net.URI uri)
Evaluation of the given URL with the PAC-file. Two cases can be handled here: DIRECT Fetch the object directly from the content HTTP server denoted by its URL PROXY name:port Fetch the object via the proxy HTTP server at the given location (name and port)- Parameters:
uri
-URI
to be evaluated.- Returns:
Proxy
-object list as result of the evaluation.
-
buildProxyFromPacResult
private java.net.Proxy buildProxyFromPacResult(java.lang.String pacResult)
The proxy evaluator will return a proxy string. This method will take this string and build a matchingProxy
for it.- Parameters:
pacResult
- the result from the PAC parser.- Returns:
- a Proxy
-
concat
private static java.lang.String concat(java.lang.String[] strings, int startIndex)
-
-