/hg/icedtea-web: 2 new changesets

omajid at icedtea.classpath.org omajid at icedtea.classpath.org
Wed Oct 9 09:22:51 PDT 2013


changeset e1509f9d7c19 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=e1509f9d7c19
author: Omair Majid <omajid at redhat.com>
date: Wed Oct 09 12:12:44 2013 -0400

	Move some proxy logic to BrowserAwareProxySelector

	The logic for mangling URIs to be compatible with the browser seems
	more appropriate to keep in the ProxySelector rather than the catch-all
	PluginAppletViewer.


changeset 6983282010ca in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=6983282010ca
author: Omair Majid <omajid at redhat.com>
date: Wed Oct 09 12:18:49 2013 -0400

	Remove duplicate key computation in proxy code


diffstat:

 ChangeLog                                                 |  21 +++++++
 plugin/icedteanp/java/sun/applet/PluginAppletViewer.java  |  37 ++----------
 plugin/icedteanp/java/sun/applet/PluginProxySelector.java |  43 +++++++++++++-
 tests/netx/unit/sun/applet/PluginAppletViewerTest.java    |  37 ------------
 tests/netx/unit/sun/applet/PluginProxySelectorTest.java   |  41 +++++++++++++-
 5 files changed, 107 insertions(+), 72 deletions(-)

diffs (298 lines):

diff -r 9424264bb603 -r 6983282010ca ChangeLog
--- a/ChangeLog	Mon Oct 07 14:02:15 2013 -0400
+++ b/ChangeLog	Wed Oct 09 12:18:49 2013 -0400
@@ -1,3 +1,24 @@
+2013-10-09  Omair Majid  <oamjid at redhat.com>
+
+	* plugin/icedteanp/java/sun/applet/PluginProxySelector.java
+	(computeKey): New method.
+	(getFromBrowser, checkCache): Call computeKey.
+
+2013-10-09  Omair Majid  <omajid at redhat.com>
+
+	* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
+	(requestPluginProxyInfo): Accept a String instead of URI.
+	(convertUriSchemeForProxyQuery): Move to ...
+	* plugin/icedteanp/java/sun/applet/PluginProxySelector.java
+	(convertUriSchemeForProxyQuery): Here.
+	(getFromBrowser): Call convertUriSchemeForProxyQuery.
+	* tests/netx/unit/sun/applet/PluginAppletViewerTest.java
+	(testConvertUriSchemeForProxyQuery),
+	(assertQueryForBrowserProxyUsesHttpFallback),
+	(assertQueryForBrowserProxyContainsNoDoubleSlashes),
+	(assertQueryForBrowserProxyDoesNotChangeQuery): Move to ...
+	* tests/netx/unit/sun/applet/PluginProxySelectorTest.java: Here.
+
 2013-10-07  Andrew Azores  <aazores at redhat.com>
 
 	DeploymentConfiguration properties reproducer fix
diff -r 9424264bb603 -r 6983282010ca plugin/icedteanp/java/sun/applet/PluginAppletViewer.java
--- a/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Mon Oct 07 14:02:15 2013 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletViewer.java	Wed Oct 09 12:18:49 2013 -0400
@@ -83,10 +83,8 @@
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
 import java.net.SocketPermission;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.AccessController;
@@ -1238,22 +1236,18 @@
         return request.getObject();
     }
 
-    public static Object requestPluginProxyInfo(URI uri) {
-
-        String requestURI = null;
+    /**
+     * Obtain information about the proxy from the browser.
+     *
+     * @param uri a String in url-encoded form
+     * @return a {@link URI} that indicates a proxy.
+     */
+    public static Object requestPluginProxyInfo(String uri) {
         Long reference = getRequestIdentifier();
 
-        try {
-            requestURI = convertUriSchemeForProxyQuery(uri);
-        } catch (Exception e) {
-            PluginDebug.debug("Cannot construct URL from ", uri.toString(), " ... falling back to DIRECT proxy");
-            OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e);
-            return null;
-        }
-
         PluginCallRequest request = requestFactory.getPluginCallRequest("proxyinfo",
                 "plugin PluginProxyInfo reference " + reference + " " +
-                        requestURI, reference);
+                        uri, reference);
 
         PluginMessageConsumer.registerPriorityWait(reference);
         streamhandler.postCallRequest(request);
@@ -1274,21 +1268,6 @@
         return request.getObject();
     }
 
-    public static String convertUriSchemeForProxyQuery(URI uri) throws URISyntaxException, UnsupportedEncodingException {
-        // there is no easy way to get SOCKS proxy info. So, we tell mozilla that we want proxy for
-        // an HTTP uri in case of non http/ftp protocols. If we get back a SOCKS proxy, we can
-        // use that, if we get back an http proxy, we fallback to DIRECT connect
-
-        String scheme = uri.getScheme();
-        if (!scheme.startsWith("http") && !scheme.equals("ftp")) {
-            scheme = "http";
-        }
-
-        URI result = new URI(scheme, uri.getUserInfo(), uri.getHost(), uri.getPort(),
-                uri.getPath(), uri.getQuery(), uri.getFragment());
-        return UrlUtil.encode(result.toString(), "UTF-8");
-    }
-
     public static void JavaScriptFinalize(long internal) {
         Long reference = getRequestIdentifier();
 
diff -r 9424264bb603 -r 6983282010ca plugin/icedteanp/java/sun/applet/PluginProxySelector.java
--- a/plugin/icedteanp/java/sun/applet/PluginProxySelector.java	Mon Oct 07 14:02:15 2013 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginProxySelector.java	Wed Oct 09 12:18:49 2013 -0400
@@ -37,12 +37,16 @@
 
 package sun.applet;
 
+import java.io.UnsupportedEncodingException;
 import java.net.InetSocketAddress;
 import java.net.Proxy;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.sun.jndi.toolkit.url.UrlUtil;
+
 import net.sourceforge.jnlp.config.DeploymentConfiguration;
 import net.sourceforge.jnlp.runtime.JNLPProxySelector;
 import net.sourceforge.jnlp.util.logging.OutputController;
@@ -84,8 +88,19 @@
         }
 
         // Nothing usable in cache. Fetch info from browser
+
+        String requestURI;
+        try {
+            requestURI = convertUriSchemeForProxyQuery(uri);
+        } catch (Exception e) {
+            PluginDebug.debug("Cannot construct URL from ", uri.toString(), " ... falling back to DIRECT proxy");
+            OutputController.getLogger().log(OutputController.Level.ERROR_ALL,e);
+            proxyList.add(Proxy.NO_PROXY);
+            return proxyList;
+        }
+
         Proxy proxy = Proxy.NO_PROXY;
-        Object o = getProxyFromRemoteCallToBrowser(uri);
+        Object o = getProxyFromRemoteCallToBrowser(requestURI);
 
         // If the browser returned anything, try to parse it. If anything in the try block fails, the fallback is direct connection
         try {
@@ -101,7 +116,7 @@
 
                     proxy = new Proxy(type, socketAddr);
 
-                    String uriKey = uri.getScheme() + "://" + uri.getHost();
+                    String uriKey = computeKey(uri);
                     proxyCache.put(uriKey, proxy);
                 } else {
                     PluginDebug.debug("Proxy ", proxyURI, " cannot be used for ", uri, ". Falling back to DIRECT");
@@ -119,7 +134,7 @@
     }
 
     /** For tests to override */
-    protected Object getProxyFromRemoteCallToBrowser(URI uri) {
+    protected Object getProxyFromRemoteCallToBrowser(String uri) {
         return PluginAppletViewer.requestPluginProxyInfo(uri);
     }
 
@@ -130,8 +145,7 @@
      * @return The cached Proxy. null if there is no suitable cached proxy.
      */
     private Proxy checkCache(URI uri) {
-
-        String uriKey = uri.getScheme() + "://" + uri.getHost();
+        String uriKey = computeKey(uri);
         if (proxyCache.get(uriKey) != null) {
             return proxyCache.get(uriKey);
         }
@@ -139,4 +153,23 @@
         return null;
     }
 
+    /** Compute a key to use for the proxy cache */
+    private String computeKey(URI uri) {
+        return uri.getScheme() + "://" + uri.getHost();
+    }
+
+    public static String convertUriSchemeForProxyQuery(URI uri) throws URISyntaxException, UnsupportedEncodingException {
+        // there is no easy way to get SOCKS proxy info. So, we tell mozilla that we want proxy for
+        // an HTTP uri in case of non http/ftp protocols. If we get back a SOCKS proxy, we can
+        // use that, if we get back an http proxy, we fallback to DIRECT connect
+
+        String scheme = uri.getScheme();
+        if (!scheme.startsWith("http") && !scheme.equals("ftp")) {
+            scheme = "http";
+        }
+
+        URI result = new URI(scheme, uri.getUserInfo(), uri.getHost(), uri.getPort(),
+                uri.getPath(), uri.getQuery(), uri.getFragment());
+        return UrlUtil.encode(result.toString(), "UTF-8");
+    }
 }
diff -r 9424264bb603 -r 6983282010ca tests/netx/unit/sun/applet/PluginAppletViewerTest.java
--- a/tests/netx/unit/sun/applet/PluginAppletViewerTest.java	Mon Oct 07 14:02:15 2013 -0400
+++ b/tests/netx/unit/sun/applet/PluginAppletViewerTest.java	Wed Oct 09 12:18:49 2013 -0400
@@ -159,43 +159,6 @@
         assertEquals(expectedReturn, call.join());
     }
 
-    @Test
-    public void testConvertUriSchemeForProxyQuery() throws Exception {
-        URI[] testUris = {
-                new URI("http", "foo.com", "/bar", null),
-                new URI("https", "foo.com", "/bar", null),
-                new URI("ftp", "foo.com", "/app/res/pub/channel.jar?i=1234", null),
-                new URI("socket", "foo.co.uk", "/bar/pub/ale.jar", null),
-        };
-
-        for (URI uri : testUris) {
-            URI result = new URI(PluginAppletViewer.convertUriSchemeForProxyQuery(uri));
-            assertQueryForBrowserProxyUsesHttpFallback(uri, result);
-            String hierarchicalPath = result.getAuthority() + result.getPath();
-            assertQueryForBrowserProxyContainsNoDoubleSlashes(hierarchicalPath);
-            assertQueryForBrowserProxyDoesNotChangeQuery(uri, result);
-        }
-    }
-
-    // Test that only HTTP is used as fallback scheme if a protocol other than HTTP(S) or FTP is specified
-    public void assertQueryForBrowserProxyUsesHttpFallback(URI expected, URI result) {
-        if (expected.getScheme().equals("ftp") || expected.getScheme().startsWith("http")) {
-            Assert.assertEquals(expected.getScheme(), result.getScheme());
-        } else {
-            Assert.assertEquals(result.getScheme(), "http");
-        }
-    }
-
-    // Test that absolute resource paths do not result in double-slashes within the URI
-    public void assertQueryForBrowserProxyContainsNoDoubleSlashes(String uri) {
-        Assert.assertFalse(uri.contains("//"));
-    }
-
-    // Test that the query string of the URI is not changed
-    public void assertQueryForBrowserProxyDoesNotChangeQuery(URI expected, URI result) {
-        Assert.assertEquals(expected.getQuery(), result.getQuery());
-    }
-
    /**************************************************************************
     *                          Test utilities                                *
     **************************************************************************/
diff -r 9424264bb603 -r 6983282010ca tests/netx/unit/sun/applet/PluginProxySelectorTest.java
--- a/tests/netx/unit/sun/applet/PluginProxySelectorTest.java	Mon Oct 07 14:02:15 2013 -0400
+++ b/tests/netx/unit/sun/applet/PluginProxySelectorTest.java	Wed Oct 09 12:18:49 2013 -0400
@@ -38,6 +38,7 @@
 package sun.applet;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
 import java.net.InetSocketAddress;
@@ -65,7 +66,7 @@
         }
 
         @Override
-        protected Object getProxyFromRemoteCallToBrowser(URI uri) {
+        protected Object getProxyFromRemoteCallToBrowser(String uri) {
             remoteCallCount++;
             return browserResponse;
         }
@@ -192,4 +193,42 @@
         assertEquals(2, proxySelector.getRemoteCallCount());
     }
 
+
+    @Test
+    public void testConvertUriSchemeForProxyQuery() throws Exception {
+        URI[] testUris = {
+                new URI("http", "foo.com", "/bar", null),
+                new URI("https", "foo.com", "/bar", null),
+                new URI("ftp", "foo.com", "/app/res/pub/channel.jar?i=1234", null),
+                new URI("socket", "foo.co.uk", "/bar/pub/ale.jar", null),
+        };
+
+        for (URI uri : testUris) {
+            URI result = new URI(PluginProxySelector.convertUriSchemeForProxyQuery(uri));
+            assertQueryForBrowserProxyUsesHttpFallback(uri, result);
+            String hierarchicalPath = result.getAuthority() + result.getPath();
+            assertQueryForBrowserProxyContainsNoDoubleSlashes(hierarchicalPath);
+            assertQueryForBrowserProxyDoesNotChangeQuery(uri, result);
+        }
+    }
+
+    // Test that only HTTP is used as fallback scheme if a protocol other than HTTP(S) or FTP is specified
+    public void assertQueryForBrowserProxyUsesHttpFallback(URI expected, URI result) {
+        if (expected.getScheme().equals("ftp") || expected.getScheme().startsWith("http")) {
+            assertEquals(expected.getScheme(), result.getScheme());
+        } else {
+            assertEquals(result.getScheme(), "http");
+        }
+    }
+
+    // Test that absolute resource paths do not result in double-slashes within the URI
+    public void assertQueryForBrowserProxyContainsNoDoubleSlashes(String uri) {
+        assertFalse(uri.contains("//"));
+    }
+
+    // Test that the query string of the URI is not changed
+    public void assertQueryForBrowserProxyDoesNotChangeQuery(URI expected, URI result) {
+        assertEquals(expected.getQuery(), result.getQuery());
+    }
+
 }


More information about the distro-pkg-dev mailing list