diff options
author | Simon Rettberg | 2017-08-01 15:45:48 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-08-01 15:45:48 +0200 |
commit | df53b12c42252be8ffe9aa1eb1a9adf3002f1545 (patch) | |
tree | f4121df496411a251edaaaa8c9550b46abc00f56 | |
parent | Minor tweaks (diff) | |
download | proxy-vole-df53b12c42252be8ffe9aa1eb1a9adf3002f1545.tar.gz proxy-vole-df53b12c42252be8ffe9aa1eb1a9adf3002f1545.tar.xz proxy-vole-df53b12c42252be8ffe9aa1eb1a9adf3002f1545.zip |
Make proxy type detection more intelligent, decouple from target protocol
13 files changed, 94 insertions, 86 deletions
diff --git a/src/main/java/com/btr/proxy/search/browser/firefox/FirefoxProxySearchStrategy.java b/src/main/java/com/btr/proxy/search/browser/firefox/FirefoxProxySearchStrategy.java index 30c3be1..de576e4 100644 --- a/src/main/java/com/btr/proxy/search/browser/firefox/FirefoxProxySearchStrategy.java +++ b/src/main/java/com/btr/proxy/search/browser/firefox/FirefoxProxySearchStrategy.java @@ -1,6 +1,7 @@ package com.btr.proxy.search.browser.firefox; import java.io.IOException; +import java.net.Proxy; import java.net.ProxySelector; import java.util.Properties; @@ -8,8 +9,6 @@ import com.btr.proxy.search.ProxySearchStrategy; import com.btr.proxy.search.desktop.DesktopProxySearchStrategy; import com.btr.proxy.search.wpad.WpadProxySearchStrategy; import com.btr.proxy.selector.direct.NoProxySelector; -import com.btr.proxy.selector.fixed.FixedProxySelector; -import com.btr.proxy.selector.fixed.FixedSocksSelector; import com.btr.proxy.selector.misc.ProtocolDispatchSelector; import com.btr.proxy.selector.whitelist.ProxyBypassListSelector; import com.btr.proxy.util.Logger; @@ -204,9 +203,16 @@ public class FirefoxProxySearchStrategy implements ProxySearchStrategy { ************************************************************************/ private void installSharedProxy(ProtocolDispatchSelector ps) { - ProxySelector httpProxy = ps.getSelector("http"); + ProxySelector httpProxy; + httpProxy = ps.getSelector("socks"); if (httpProxy != null) { ps.setFallbackSelector(httpProxy); + return; + } + httpProxy = ps.getSelector("http"); + if (httpProxy != null) { + ps.setFallbackSelector(httpProxy); + return; } } @@ -218,12 +224,7 @@ public class FirefoxProxySearchStrategy implements ProxySearchStrategy { private void installSocksProxy(ProtocolDispatchSelector ps, Properties settings) throws NumberFormatException { - String proxyHost = settings.getProperty("network.proxy.socks", null); - int proxyPort = Integer.parseInt(settings.getProperty("network.proxy.socks_port", "0")); - if (proxyHost != null && proxyPort != 0) { - Logger.log(getClass(), LogLevel.TRACE, "Firefox socks proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector("socks", new FixedSocksSelector(proxyHost, proxyPort)); - } + installSelectorForProtocol(ps, settings, "socks"); } /************************************************************************* @@ -236,10 +237,11 @@ public class FirefoxProxySearchStrategy implements ProxySearchStrategy { Properties settings) throws NumberFormatException { String proxyHost = settings.getProperty("network.proxy.ssl", null); int proxyPort = Integer.parseInt(settings.getProperty("network.proxy.ssl_port", "0")); - if (proxyHost != null && proxyPort != 0) { + if (proxyHost != null) { Logger.log(getClass(), LogLevel.TRACE, "Firefox secure proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector("https", new FixedProxySelector(proxyHost, proxyPort)); - ps.setSelector("sftp", new FixedProxySelector(proxyHost, proxyPort)); + ProxySelector p = ProxyUtil.parseProxySettings(proxyHost, Proxy.Type.HTTP, proxyPort); + ps.setSelector("https", p); + ps.setSelector("sftp", p); } } @@ -257,9 +259,9 @@ public class FirefoxProxySearchStrategy implements ProxySearchStrategy { String proxyHost = settings.getProperty("network.proxy."+protocol, null); int proxyPort = Integer.parseInt(settings.getProperty("network.proxy."+protocol+"_port", "0")); - if (proxyHost != null && proxyPort != 0) { + if (proxyHost != null) { Logger.log(getClass(), LogLevel.TRACE, "Firefox "+protocol+" proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector(protocol, new FixedProxySelector(proxyHost, proxyPort)); + ps.setSelector(protocol, ProxyUtil.parseProxySettings(proxyHost, Proxy.Type.HTTP, proxyPort)); } } diff --git a/src/main/java/com/btr/proxy/search/browser/ie/IEProxySearchStrategy.java b/src/main/java/com/btr/proxy/search/browser/ie/IEProxySearchStrategy.java index 1a85495..6641aff 100644 --- a/src/main/java/com/btr/proxy/search/browser/ie/IEProxySearchStrategy.java +++ b/src/main/java/com/btr/proxy/search/browser/ie/IEProxySearchStrategy.java @@ -2,6 +2,7 @@ package com.btr.proxy.search.browser.ie; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.net.Proxy; import java.net.ProxySelector; import java.util.ArrayList; import java.util.List; @@ -179,7 +180,8 @@ public class IEProxySearchStrategy implements ProxySearchStrategy { private void addSelectorForProtocol(Properties settings, String protocol, ProtocolDispatchSelector ps) { String proxy = settings.getProperty(protocol); if (proxy != null) { - FixedProxySelector protocolSelector = ProxyUtil.parseProxySettings(proxy); + Proxy.Type fb = protocol.startsWith("socks") ? Proxy.Type.SOCKS : Proxy.Type.HTTP; + ProxySelector protocolSelector = ProxyUtil.parseProxySettings(proxy, fb, 0); ps.setSelector(protocol, protocolSelector); } } diff --git a/src/main/java/com/btr/proxy/search/desktop/gnome/GnomeProxySearchStrategy.java b/src/main/java/com/btr/proxy/search/desktop/gnome/GnomeProxySearchStrategy.java index 240fb39..10d237a 100644 --- a/src/main/java/com/btr/proxy/search/desktop/gnome/GnomeProxySearchStrategy.java +++ b/src/main/java/com/btr/proxy/search/desktop/gnome/GnomeProxySearchStrategy.java @@ -2,6 +2,7 @@ package com.btr.proxy.search.desktop.gnome; import java.io.File; import java.io.IOException; +import java.net.Proxy; import java.net.ProxySelector; import java.util.Properties; @@ -17,14 +18,13 @@ import org.xml.sax.SAXException; import com.btr.proxy.search.ProxySearchStrategy; import com.btr.proxy.selector.direct.NoProxySelector; -import com.btr.proxy.selector.fixed.FixedProxySelector; import com.btr.proxy.selector.misc.ProtocolDispatchSelector; import com.btr.proxy.selector.whitelist.ProxyBypassListSelector; import com.btr.proxy.util.EmptyXMLResolver; import com.btr.proxy.util.Logger; +import com.btr.proxy.util.Logger.LogLevel; import com.btr.proxy.util.ProxyException; import com.btr.proxy.util.ProxyUtil; -import com.btr.proxy.util.Logger.LogLevel; /***************************************************************************** * Loads the Gnome proxy settings from the Gnome GConf settings. @@ -219,9 +219,9 @@ public class GnomeProxySearchStrategy implements ProxySearchStrategy { ProtocolDispatchSelector ps) throws NumberFormatException { String proxyHost = settings.getProperty("/system/http_proxy/host", null); int proxyPort = Integer.parseInt(settings.getProperty("/system/http_proxy/port", "0").trim()); - if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { + if (proxyHost != null && proxyHost.length() > 0) { Logger.log(getClass(), LogLevel.TRACE, "Gnome http proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector("http", new FixedProxySelector(proxyHost.trim(), proxyPort)); + ps.setSelector("http", ProxyUtil.parseProxySettings(proxyHost.trim(), Proxy.Type.HTTP, proxyPort)); } } @@ -236,9 +236,9 @@ public class GnomeProxySearchStrategy implements ProxySearchStrategy { ProtocolDispatchSelector ps) throws NumberFormatException { String proxyHost = settings.getProperty("/system/proxy/socks_host", null); int proxyPort = Integer.parseInt(settings.getProperty("/system/proxy/socks_port", "0").trim()); - if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { + if (proxyHost != null && proxyHost.length() > 0) { Logger.log(getClass(), LogLevel.TRACE, "Gnome socks proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector("socks", new FixedProxySelector(proxyHost.trim(), proxyPort)); + ps.setSelector("socks", ProxyUtil.parseProxySettings(proxyHost.trim(), Proxy.Type.SOCKS, proxyPort)); } } @@ -252,9 +252,9 @@ public class GnomeProxySearchStrategy implements ProxySearchStrategy { ProtocolDispatchSelector ps) throws NumberFormatException { String proxyHost = settings.getProperty("/system/proxy/ftp_host", null); int proxyPort = Integer.parseInt(settings.getProperty("/system/proxy/ftp_port", "0").trim()); - if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { + if (proxyHost != null && proxyHost.length() > 0) { Logger.log(getClass(), LogLevel.TRACE, "Gnome ftp proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector("ftp", new FixedProxySelector(proxyHost.trim(), proxyPort)); + ps.setSelector("ftp", ProxyUtil.parseProxySettings(proxyHost.trim(), Proxy.Type.HTTP, proxyPort)); } } @@ -269,10 +269,11 @@ public class GnomeProxySearchStrategy implements ProxySearchStrategy { ProtocolDispatchSelector ps) throws NumberFormatException { String proxyHost = settings.getProperty("/system/proxy/secure_host", null); int proxyPort = Integer.parseInt(settings.getProperty("/system/proxy/secure_port", "0").trim()); - if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) { + if (proxyHost != null && proxyHost.length() > 0) { Logger.log(getClass(), LogLevel.TRACE, "Gnome secure proxy is {0}:{1}", proxyHost, proxyPort); - ps.setSelector("https", new FixedProxySelector(proxyHost.trim(), proxyPort)); - ps.setSelector("sftp", new FixedProxySelector(proxyHost.trim(), proxyPort)); + ProxySelector ps2 = ProxyUtil.parseProxySettings(proxyHost.trim(), Proxy.Type.HTTP, proxyPort); + ps.setSelector("https", ps2); + ps.setSelector("sftp", ps2); } } diff --git a/src/main/java/com/btr/proxy/search/desktop/kde/KdeProxySearchStrategy.java b/src/main/java/com/btr/proxy/search/desktop/kde/KdeProxySearchStrategy.java index e05d72e..de81c4c 100644 --- a/src/main/java/com/btr/proxy/search/desktop/kde/KdeProxySearchStrategy.java +++ b/src/main/java/com/btr/proxy/search/desktop/kde/KdeProxySearchStrategy.java @@ -154,7 +154,7 @@ public class KdeProxySearchStrategy implements ProxySearchStrategy { private ProxySelector setupFixedProxySelector(Properties settings) { String proxyVar = settings.getProperty("httpProxy", null); - FixedProxySelector httpPS = ProxyUtil.parseProxySettings(proxyVar); + ProxySelector httpPS = ProxyUtil.parseProxySettings(proxyVar); if (httpPS == null) { Logger.log(getClass(), LogLevel.TRACE, "Kde http proxy is {0}", proxyVar); return null; @@ -164,14 +164,14 @@ public class KdeProxySearchStrategy implements ProxySearchStrategy { ps.setSelector("http", httpPS); proxyVar = settings.getProperty("httpsProxy", null); - FixedProxySelector httpsPS = ProxyUtil.parseProxySettings(proxyVar); + ProxySelector httpsPS = ProxyUtil.parseProxySettings(proxyVar); if (httpsPS != null) { Logger.log(getClass(), LogLevel.TRACE, "Kde https proxy is {0}", proxyVar); ps.setSelector("https", httpsPS); } proxyVar = settings.getProperty("ftpProxy", null); - FixedProxySelector ftpPS = ProxyUtil.parseProxySettings(proxyVar); + ProxySelector ftpPS = ProxyUtil.parseProxySettings(proxyVar); if (ftpPS != null) { Logger.log(getClass(), LogLevel.TRACE, "Kde ftp proxy is {0}", proxyVar); ps.setSelector("ftp", ftpPS); diff --git a/src/main/java/com/btr/proxy/search/desktop/osx/OsxProxySearchStrategy.java b/src/main/java/com/btr/proxy/search/desktop/osx/OsxProxySearchStrategy.java index 3d67ae7..71d7a8f 100644 --- a/src/main/java/com/btr/proxy/search/desktop/osx/OsxProxySearchStrategy.java +++ b/src/main/java/com/btr/proxy/search/desktop/osx/OsxProxySearchStrategy.java @@ -3,6 +3,7 @@ package com.btr.proxy.search.desktop.osx; import java.io.File; import java.io.IOException; import java.net.NetworkInterface; +import java.net.Proxy; import java.net.ProxySelector; import java.net.SocketException; import java.util.ArrayList; @@ -14,8 +15,6 @@ import com.btr.proxy.search.ProxySearchStrategy; import com.btr.proxy.search.browser.ie.IELocalByPassFilter; import com.btr.proxy.search.wpad.WpadProxySearchStrategy; import com.btr.proxy.selector.direct.NoProxySelector; -import com.btr.proxy.selector.fixed.FixedProxySelector; -import com.btr.proxy.selector.fixed.FixedSocksSelector; import com.btr.proxy.selector.misc.ProtocolDispatchSelector; import com.btr.proxy.selector.whitelist.ProxyBypassListSelector; import com.btr.proxy.util.Logger; @@ -288,7 +287,7 @@ public class OsxProxySearchStrategy implements ProxySearchStrategy { if (isActive(proxySettings.get("SOCKSEnable"))) { String proxyHost = (String) proxySettings.get("SOCKSProxy"); int proxyPort = (Integer) proxySettings.get("SOCKSPort"); - ps.setSelector("socks", new FixedSocksSelector(proxyHost, proxyPort)); + ps.setSelector("socks", ProxyUtil.parseProxySettings(proxyHost.trim(), Proxy.Type.SOCKS, proxyPort)); Logger.log(getClass(), LogLevel.TRACE, "OSX socks proxy is {0}:{1}", proxyHost, proxyPort); } } @@ -306,7 +305,7 @@ public class OsxProxySearchStrategy implements ProxySearchStrategy { if (isActive(proxySettings.get(prefix+"Enable"))) { String proxyHost = (String) proxySettings.get(prefix+"Proxy"); int proxyPort = (Integer) proxySettings.get(prefix+"Port"); - FixedProxySelector fp = new FixedProxySelector(proxyHost, proxyPort); + ProxySelector fp = ProxyUtil.parseProxySettings(proxyHost.trim(), Proxy.Type.HTTP, proxyPort); ps.setSelector(protocol.toLowerCase(), fp); Logger.log(getClass(), LogLevel.TRACE, "OSX uses for {0} the proxy {1}:{2}", protocol, proxyHost, proxyPort); } diff --git a/src/main/java/com/btr/proxy/search/java/JavaProxySearchStrategy.java b/src/main/java/com/btr/proxy/search/java/JavaProxySearchStrategy.java index 531ef94..f1853b7 100644 --- a/src/main/java/com/btr/proxy/search/java/JavaProxySearchStrategy.java +++ b/src/main/java/com/btr/proxy/search/java/JavaProxySearchStrategy.java @@ -1,10 +1,10 @@ package com.btr.proxy.search.java; +import java.net.Proxy; import java.net.ProxySelector; import com.btr.proxy.search.ProxySearchStrategy; import com.btr.proxy.selector.fixed.FixedProxySelector; -import com.btr.proxy.selector.fixed.FixedSocksSelector; import com.btr.proxy.selector.misc.ProtocolDispatchSelector; import com.btr.proxy.selector.whitelist.ProxyBypassListSelector; import com.btr.proxy.util.Logger; @@ -96,7 +96,7 @@ public class JavaProxySearchStrategy implements ProxySearchStrategy { String port = System.getProperty("socksProxyPort", "1080"); if (host != null && host.trim().length() > 0) { Logger.log(getClass(), LogLevel.TRACE, "Socks proxy {0}:{1} found", host, port); - ps.setSelector("socks", new FixedSocksSelector(host, Integer.parseInt(port))); + ps.setSelector("socks", new FixedProxySelector(Proxy.Type.SOCKS, host, Integer.parseInt(port))); } } @@ -122,7 +122,7 @@ public class JavaProxySearchStrategy implements ProxySearchStrategy { Logger.log(getClass(), LogLevel.TRACE, protocol.toUpperCase()+" proxy {0}:{1} found using whitelist: {2}", host, port, whiteList); - ProxySelector protocolSelector = new FixedProxySelector(host, Integer.parseInt(port)); + ProxySelector protocolSelector = new FixedProxySelector(Proxy.Type.HTTP, host, Integer.parseInt(port)); if (whiteList.trim().length() > 0) { protocolSelector = new ProxyBypassListSelector(whiteList, protocolSelector); } diff --git a/src/main/java/com/btr/proxy/selector/fixed/FixedProxySelector.java b/src/main/java/com/btr/proxy/selector/fixed/FixedProxySelector.java index 498ac52..2de95b5 100644 --- a/src/main/java/com/btr/proxy/selector/fixed/FixedProxySelector.java +++ b/src/main/java/com/btr/proxy/selector/fixed/FixedProxySelector.java @@ -41,8 +41,8 @@ public class FixedProxySelector extends ProxySelector { * @param proxyPort the port of the proxy. ************************************************************************/ - public FixedProxySelector(String proxyHost, int proxyPort) { - this(new Proxy(Proxy.Type.HTTP, + public FixedProxySelector(Proxy.Type type, String proxyHost, int proxyPort) { + this(new Proxy(type, InetSocketAddress.createUnresolved(proxyHost, proxyPort))); } diff --git a/src/main/java/com/btr/proxy/selector/fixed/FixedSocksSelector.java b/src/main/java/com/btr/proxy/selector/fixed/FixedSocksSelector.java deleted file mode 100644 index d1f7ccc..0000000 --- a/src/main/java/com/btr/proxy/selector/fixed/FixedSocksSelector.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.btr.proxy.selector.fixed; - -import java.net.InetSocketAddress; -import java.net.Proxy; - -/***************************************************************************** - * This proxy selector is configured with a fixed proxy. This proxy will be - * returned for all URIs passed to the select method. This implementation - * can be used for SOCKS 4 and 5 proxy support. - * - * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009 - ****************************************************************************/ - -public class FixedSocksSelector extends FixedProxySelector { - - /************************************************************************* - * Constructor - * @param proxyHost the host name or IP address of the proxy to use. - * @param proxyPort the port of the proxy. - ************************************************************************/ - - public FixedSocksSelector(String proxyHost, int proxyPort) { - super(new Proxy(Proxy.Type.SOCKS, - InetSocketAddress.createUnresolved(proxyHost, proxyPort))); - } - -} diff --git a/src/main/java/com/btr/proxy/selector/misc/ProtocolDispatchSelector.java b/src/main/java/com/btr/proxy/selector/misc/ProtocolDispatchSelector.java index 5d7f563..02ecc44 100644 --- a/src/main/java/com/btr/proxy/selector/misc/ProtocolDispatchSelector.java +++ b/src/main/java/com/btr/proxy/selector/misc/ProtocolDispatchSelector.java @@ -104,11 +104,18 @@ public class ProtocolDispatchSelector extends ProxySelector { @Override public List<Proxy> select(URI uri) { - ProxySelector selector = this.fallbackSelector; + ProxySelector selector = null; String protocol = uri.getScheme(); if (protocol != null && this.selectors.get(protocol) != null) { selector = this.selectors.get(protocol); } + if (selector == null && this.selectors.get("socks") != null) { + // Socks should always work + selector = this.selectors.get("socks"); + } + if (selector == null) { + selector = this.fallbackSelector; + } return selector.select(uri); } diff --git a/src/main/java/com/btr/proxy/selector/pac/PacProxySelector.java b/src/main/java/com/btr/proxy/selector/pac/PacProxySelector.java index 40469b0..765a376 100644 --- a/src/main/java/com/btr/proxy/selector/pac/PacProxySelector.java +++ b/src/main/java/com/btr/proxy/selector/pac/PacProxySelector.java @@ -167,7 +167,7 @@ public class PacProxySelector extends ProxySelector { }
String host = proxyDef.substring(6);
- Integer port = ProxyUtil.DEFAULT_PROXY_PORT;
+ Integer port = ProxyUtil.DEFAULT_HTTP_PROXY_PORT;
// Split port from host
int indexOfPort = host.indexOf(':');
diff --git a/src/main/java/com/btr/proxy/util/ProxyUtil.java b/src/main/java/com/btr/proxy/util/ProxyUtil.java index 6bbaa30..bd3680d 100644 --- a/src/main/java/com/btr/proxy/util/ProxyUtil.java +++ b/src/main/java/com/btr/proxy/util/ProxyUtil.java @@ -1,6 +1,7 @@ package com.btr.proxy.util; import java.net.Proxy; +import java.net.ProxySelector; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -22,10 +23,12 @@ import com.btr.proxy.util.Logger.LogLevel; public class ProxyUtil { - public static final int DEFAULT_PROXY_PORT = 80; + public static final int DEFAULT_HTTP_PROXY_PORT = 80; + + public static final int DEFAULT_SOCKS_PROXY_PORT = 1080; private static List<Proxy> noProxyList; - private static Pattern pattern = Pattern.compile("\\w*?:?/*([^:/]+):?(\\d*)/?"); + private static Pattern pattern = Pattern.compile("^\\s*(\\w*?):?/*([^:/]+):?(\\d*)/?"); /************************************************************************* * Parse host and port out of a proxy variable. @@ -34,20 +37,41 @@ public class ProxyUtil { * @return a FixedProxySelector using this settings, null on parse error. ************************************************************************/ - public static FixedProxySelector parseProxySettings(String proxyVar) { + public static ProxySelector parseProxySettings(String proxyVar) { + return parseProxySettings(proxyVar, Proxy.Type.HTTP, 0); + } + + public static ProxySelector parseProxySettings(String proxyVar, Proxy.Type fallback, int fallbackPort) { if (proxyVar == null || proxyVar.trim().length() == 0) { return null; } Matcher matcher = pattern.matcher(proxyVar); if (matcher.matches()) { - String host = matcher.group(1); - int port; - if (!"".equals(matcher.group(2))) { - port = Integer.parseInt(matcher.group(2)); + String host = matcher.group(2); + int port = -1; + if (!"".equals(matcher.group(3))) { + port = Integer.parseInt(matcher.group(3)); + } + String stype = matcher.group(1).toLowerCase(); + Proxy.Type type; + if (stype.isEmpty()) { + type = fallback; + } else if (stype.startsWith("socks")) { + type = Proxy.Type.SOCKS; } else { - port = DEFAULT_PROXY_PORT; + type = Proxy.Type.HTTP; + } + if (port == -1 && fallbackPort > 0) { + port = fallbackPort; + } + if (port == -1) { + if (type == Proxy.Type.HTTP) { + port = DEFAULT_HTTP_PROXY_PORT; + } else if (type == Proxy.Type.SOCKS) { + port = DEFAULT_SOCKS_PROXY_PORT; + } } - return new FixedProxySelector(host.trim(), port); + return new FixedProxySelector(type, host.trim(), port); } else { return null; } diff --git a/src/test/java/com/btr/proxy/selector/fixed/FixedProxyTest.java b/src/test/java/com/btr/proxy/selector/fixed/FixedProxyTest.java index c4a7d08..017f669 100644 --- a/src/test/java/com/btr/proxy/selector/fixed/FixedProxyTest.java +++ b/src/test/java/com/btr/proxy/selector/fixed/FixedProxyTest.java @@ -1,6 +1,6 @@ package com.btr.proxy.selector.fixed; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.net.Proxy; import java.net.ProxySelector; @@ -23,7 +23,7 @@ public class FixedProxyTest { ************************************************************************/ @Test public void testFixedProxy() { - ProxySelector ps = new FixedProxySelector("http_proxy.unit-test.invalid", 8090); + ProxySelector ps = new FixedProxySelector(Proxy.Type.HTTP, "http_proxy.unit-test.invalid", 8090); List<Proxy> result = ps.select(TestUtil.HTTP_TEST_URI); assertEquals(TestUtil.HTTP_TEST_PROXY, result.get(0)); diff --git a/src/test/java/com/btr/proxy/util/ProxyUtilTest.java b/src/test/java/com/btr/proxy/util/ProxyUtilTest.java index d8e10c5..5634600 100644 --- a/src/test/java/com/btr/proxy/util/ProxyUtilTest.java +++ b/src/test/java/com/btr/proxy/util/ProxyUtilTest.java @@ -1,14 +1,14 @@ package com.btr.proxy.util; -import static junit.framework.Assert.*; +import static junit.framework.Assert.assertEquals; import java.net.Proxy; +import java.net.ProxySelector; import java.util.List; import org.junit.Test; import com.btr.proxy.TestUtil; -import com.btr.proxy.selector.fixed.FixedProxySelector; /***************************************************************************** @@ -24,7 +24,7 @@ public class ProxyUtilTest { @Test public void testParseProxySettings() { - FixedProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid/"); + ProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid/"); List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI); assertEquals("HTTP @ http_proxy.unit-test.invalid:80", psList.get(0).toString()); } @@ -35,9 +35,9 @@ public class ProxyUtilTest { @Test public void testParseProxySettings2() { - FixedProxySelector rs = ProxyUtil.parseProxySettings("http://http_proxy.unit-test.invalid:8080/"); + ProxySelector rs = ProxyUtil.parseProxySettings("socks://http_proxy.unit-test.invalid:8080/"); List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI); - assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString()); + assertEquals("SOCKS @ http_proxy.unit-test.invalid:8080", psList.get(0).toString()); } /************************************************************************* @@ -46,7 +46,7 @@ public class ProxyUtilTest { @Test public void testParseProxySettings3() { - FixedProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid"); + ProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid"); List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI); assertEquals("HTTP @ http_proxy.unit-test.invalid:80", psList.get(0).toString()); } @@ -57,7 +57,7 @@ public class ProxyUtilTest { @Test public void testParseProxySettings4() { - FixedProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid:8080"); + ProxySelector rs = ProxyUtil.parseProxySettings("http_proxy.unit-test.invalid:8080"); List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI); assertEquals("HTTP @ http_proxy.unit-test.invalid:8080", psList.get(0).toString()); } @@ -68,7 +68,7 @@ public class ProxyUtilTest { @Test public void testParseProxySettings5() { - FixedProxySelector rs = ProxyUtil.parseProxySettings("192.123.123.1:8080"); + ProxySelector rs = ProxyUtil.parseProxySettings("192.123.123.1:8080"); List<Proxy> psList = rs.select(TestUtil.HTTP_TEST_URI); assertEquals("HTTP @ 192.123.123.1:8080", psList.get(0).toString()); } |