diff options
Diffstat (limited to 'netx/net')
3 files changed, 52 insertions, 43 deletions
diff --git a/netx/net/sourceforge/jnlp/browser/BrowserAwareProxySelector.java b/netx/net/sourceforge/jnlp/browser/BrowserAwareProxySelector.java index 926a591..1f51ea6 100644 --- a/netx/net/sourceforge/jnlp/browser/BrowserAwareProxySelector.java +++ b/netx/net/sourceforge/jnlp/browser/BrowserAwareProxySelector.java @@ -40,13 +40,10 @@ import static net.sourceforge.jnlp.runtime.Translator.R; import java.io.File; import java.io.IOException; -import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.Proxy; -import java.net.SocketAddress; import java.net.URI; import java.net.URL; -import java.net.Proxy.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -79,6 +76,7 @@ public class BrowserAwareProxySelector extends JNLPProxySelector { private int browserProxyType = BROWSER_PROXY_TYPE_NONE; private URL browserAutoConfigUrl; + /** Whether the http proxy should be used for http, https, ftp and socket protocols */ private Boolean browserUseSameProxy; private String browserHttpProxyHost; private int browserHttpProxyPort; @@ -96,6 +94,9 @@ public class BrowserAwareProxySelector extends JNLPProxySelector { */ public BrowserAwareProxySelector(DeploymentConfiguration config) { super(config); + } + + public void initialize() { try { initFromBrowserConfig(); } catch (IOException e) { @@ -110,11 +111,7 @@ public class BrowserAwareProxySelector extends JNLPProxySelector { */ private void initFromBrowserConfig() throws IOException { - File preferencesFile = FirefoxPreferencesFinder.find(); - - FirefoxPreferencesParser parser = new FirefoxPreferencesParser(preferencesFile); - parser.parse(); - Map<String, String> prefs = parser.getPreferences(); + Map<String, String> prefs = parseBrowserPreferences(); String type = prefs.get("network.proxy.type"); if (type != null) { @@ -150,6 +147,13 @@ public class BrowserAwareProxySelector extends JNLPProxySelector { browserSocks4ProxyPort = stringToPort(prefs.get("network.proxy.socks_port")); } + Map<String, String> parseBrowserPreferences() throws IOException { + File preferencesFile = FirefoxPreferencesFinder.find(); + FirefoxPreferencesParser parser = new FirefoxPreferencesParser(preferencesFile); + parser.parse(); + return parser.getPreferences(); + } + /** * Returns port inside a string. Unlike {@link Integer#valueOf(String)}, * it will not throw exceptions. @@ -244,36 +248,11 @@ public class BrowserAwareProxySelector extends JNLPProxySelector { * the browser's preferences file. */ private List<Proxy> getFromBrowserConfiguration(URI uri) { - List<Proxy> proxies = new ArrayList<Proxy>(); - - String scheme = uri.getScheme(); - - if (browserUseSameProxy) { - SocketAddress sa = new InetSocketAddress(browserHttpProxyHost, browserHttpProxyPort); - Proxy proxy; - if (scheme.equals("socket")) { - proxy = new Proxy(Type.SOCKS, sa); - } else { - proxy = new Proxy(Type.HTTP, sa); - } - proxies.add(proxy); - } else if (scheme.equals("http")) { - SocketAddress sa = new InetSocketAddress(browserHttpProxyHost, browserHttpProxyPort); - proxies.add(new Proxy(Type.HTTP, sa)); - } else if (scheme.equals("https")) { - SocketAddress sa = new InetSocketAddress(browserHttpsProxyHost, browserHttpsProxyPort); - proxies.add(new Proxy(Type.HTTP, sa)); - } else if (scheme.equals("ftp")) { - SocketAddress sa = new InetSocketAddress(browserFtpProxyHost, browserFtpProxyPort); - proxies.add(new Proxy(Type.HTTP, sa)); - } else if (scheme.equals("socket")) { - SocketAddress sa = new InetSocketAddress(browserSocks4ProxyHost, browserSocks4ProxyPort); - proxies.add(new Proxy(Type.SOCKS, sa)); - } else { - proxies.add(Proxy.NO_PROXY); - } - - return proxies; + return getFromArguments(uri, browserUseSameProxy, true, + browserHttpsProxyHost, browserHttpsProxyPort, + browserHttpProxyHost, browserHttpProxyPort, + browserFtpProxyHost, browserFtpProxyPort, + browserSocks4ProxyHost, browserSocks4ProxyPort); } } diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java b/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java index e92b2c9..4fb760a 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java @@ -288,15 +288,42 @@ public abstract class JNLPProxySelector extends ProxySelector { * @return a List of Proxy objects */ private List<Proxy> getFromConfiguration(URI uri) { + return getFromArguments(uri, sameProxy, false, + proxyHttpsHost, proxyHttpsPort, + proxyHttpHost, proxyHttpPort, + proxyFtpHost, proxyFtpPort, + proxySocks4Host, proxySocks4Port); + } + + /** + * Returns a list of proxies by using the arguments + * + * @return a List of Proxy objects + */ + protected static List<Proxy> getFromArguments(URI uri, + boolean sameProxy, boolean sameProxyIncludesSocket, + String proxyHttpsHost, int proxyHttpsPort, + String proxyHttpHost, int proxyHttpPort, + String proxyFtpHost, int proxyFtpPort, + String proxySocks4Host, int proxySocks4Port) { + List<Proxy> proxies = new ArrayList<Proxy>(); String scheme = uri.getScheme(); + boolean socksProxyAdded = false; + if (sameProxy) { - if (proxyHttpHost != null && (scheme.equals("https") || scheme.equals("http") || scheme.equals("ftp"))) { + if (proxyHttpHost != null) { SocketAddress sa = new InetSocketAddress(proxyHttpHost, proxyHttpPort); - Proxy proxy = new Proxy(Type.HTTP, sa); - proxies.add(proxy); + if ((scheme.equals("https") || scheme.equals("http") || scheme.equals("ftp"))) { + Proxy proxy = new Proxy(Type.HTTP, sa); + proxies.add(proxy); + } else if (scheme.equals("socket") && sameProxyIncludesSocket) { + Proxy proxy = new Proxy(Type.SOCKS, sa); + proxies.add(proxy); + socksProxyAdded = true; + } } } else if (scheme.equals("http") && proxyHttpHost != null) { SocketAddress sa = new InetSocketAddress(proxyHttpHost, proxyHttpPort); @@ -309,9 +336,10 @@ public abstract class JNLPProxySelector extends ProxySelector { proxies.add(new Proxy(Type.HTTP, sa)); } - if (proxySocks4Host != null) { + if (!socksProxyAdded && (proxySocks4Host != null)) { SocketAddress sa = new InetSocketAddress(proxySocks4Host, proxySocks4Port); proxies.add(new Proxy(Type.SOCKS, sa)); + socksProxyAdded = true; } if (proxies.size() == 0) { diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index a79663b..9045c83 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -266,7 +266,9 @@ public class JNLPRuntime { // plug in a custom authenticator and proxy selector Authenticator.setDefault(new JNLPAuthenticator()); - ProxySelector.setDefault(new BrowserAwareProxySelector(config)); + BrowserAwareProxySelector proxySelector = new BrowserAwareProxySelector(config); + proxySelector.initialize(); + ProxySelector.setDefault(proxySelector); // Restrict access to netx classes Security.setProperty("package.access", |