Package com.github.markusbernhardt.proxy
Class ProxySearch
- java.lang.Object
-
- com.github.markusbernhardt.proxy.ProxySearch
-
- All Implemented Interfaces:
ProxySearchStrategy
public class ProxySearch extends java.lang.Object implements ProxySearchStrategy
Main class to setup and initialize the proxy detection system.
This class can be used to select a proxy discovery strategy.
Implements the "Builder" pattern.
UseaddStrategy
to add one or more search strategies.
If you are done call thegetProxySelector
method.
Then the strategies are asked one after the other for a ProxySelector until an valid selector is found.
Invoke the static
getDefaultProxySearch
method to use a default search strategy.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProxySearch.Strategy
Types of proxy detection supported by the builder.
-
Field Summary
Fields Modifier and Type Field Description private static BufferedProxySelector.CacheScope
DEFAULT_PAC_CACHE_SCOPE
private static int
DEFAULT_PAC_CACHE_SIZE
private static long
DEFAULT_PAC_CACHE_TTL
private BufferedProxySelector.CacheScope
pacCacheScope
private int
pacCacheSize
private long
pacCacheTTL
private java.util.List<ProxySearchStrategy>
strategies
-
Constructor Summary
Constructors Constructor Description ProxySearch()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStrategy(ProxySearch.Strategy strategy)
Adds an search strategy to the list of proxy searches strategies.private ProxySearchStrategy
getDefaultBrowserStrategy()
Gets the search strategy for the platforms default browser.static ProxySearch
getDefaultProxySearch()
Sets up a ProxySearch that uses a default search strategy suitable for every platform.java.lang.String
getName()
Gets the printable name of the search strategy.java.net.ProxySelector
getProxySelector()
Gets the proxy selector that will use the configured search order.private java.net.ProxySelector
installBufferingAndFallbackBehaviour(java.net.ProxySelector selector)
If it is PAC and we have caching enabled set it here.static void
main(java.lang.String[] args)
For testing only.void
setPacCacheSettings(int size, long ttl, BufferedProxySelector.CacheScope cacheScope)
Sets the cache size of the PAC proxy selector cache.java.lang.String
toString()
toString
-
-
-
Field Detail
-
DEFAULT_PAC_CACHE_SIZE
private static final int DEFAULT_PAC_CACHE_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_PAC_CACHE_TTL
private static final long DEFAULT_PAC_CACHE_TTL
- See Also:
- Constant Field Values
-
DEFAULT_PAC_CACHE_SCOPE
private static final BufferedProxySelector.CacheScope DEFAULT_PAC_CACHE_SCOPE
-
strategies
private java.util.List<ProxySearchStrategy> strategies
-
pacCacheSize
private int pacCacheSize
-
pacCacheTTL
private long pacCacheTTL
-
pacCacheScope
private BufferedProxySelector.CacheScope pacCacheScope
-
-
Method Detail
-
getDefaultProxySearch
public static ProxySearch getDefaultProxySearch()
Sets up a ProxySearch that uses a default search strategy suitable for every platform.- Returns:
- a ProxySearch initialized with default settings.
-
addStrategy
public void addStrategy(ProxySearch.Strategy strategy)
Adds an search strategy to the list of proxy searches strategies.- Parameters:
strategy
- the search strategy to add.
-
setPacCacheSettings
public void setPacCacheSettings(int size, long ttl, BufferedProxySelector.CacheScope cacheScope)
Sets the cache size of the PAC proxy selector cache. This defines the number of URLs that are cached together with the PAC script result. This improves performance because for URLs that are in the cache the script is not executed again. You have to set this before you add any strategies that may create a PAC script proxy selector.- Parameters:
size
- of the cache. Set it to 0 to disable caching.ttl
- is the time to live of the cache entries as amount of milliseconds.cacheScope
- the desired cache scope.
-
getDefaultBrowserStrategy
private ProxySearchStrategy getDefaultBrowserStrategy()
Gets the search strategy for the platforms default browser.- Returns:
- a ProxySearchStrategy, null if no supported browser was found.
-
getProxySelector
public java.net.ProxySelector getProxySelector()
Gets the proxy selector that will use the configured search order.- Specified by:
getProxySelector
in interfaceProxySearchStrategy
- Returns:
- a ProxySelector, null if none was found for the current builder configuration.
-
getName
public java.lang.String getName()
Gets the printable name of the search strategy.- Specified by:
getName
in interfaceProxySearchStrategy
- Returns:
- the printable name of the search strategy
-
installBufferingAndFallbackBehaviour
private java.net.ProxySelector installBufferingAndFallbackBehaviour(java.net.ProxySelector selector)
If it is PAC and we have caching enabled set it here.- Parameters:
selector
- the proxy selector to wrap- Returns:
- the wrapped proxy selector or the passed in selector if nothing is done.
-
toString
public java.lang.String toString()
toString- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
main
public static void main(java.lang.String[] args)
For testing only. Will print the logging & proxy information to the console.- Parameters:
args
- the command line arguments.
-
-