From 961bb03aaf6b8851792b6a42942f4cf403d79483 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 27 Oct 2016 10:12:51 -0500 Subject: Bug 506460 - openConnection(URL u, Proxy p) is unsupported when multiple frameworks are running Change-Id: I44b31638002212d08a0a47bd4d9511d88420cc3b Signed-off-by: Thomas Watson --- .../org.eclipse.osgi.tests/META-INF/MANIFEST.MF | 2 +- .../bundles_src/geturl/geturl/Activator.java | 13 +++++++---- bundles/org.eclipse.osgi.tests/pom.xml | 2 +- .../osgi/tests/bundles/SystemBundleTests.java | 5 +++++ bundles/org.eclipse.osgi/META-INF/MANIFEST.MF | 2 +- .../internal/url/MultiplexingURLStreamHandler.java | 25 +++++++++++++++++++++- .../osgi/internal/url/URLStreamHandlerProxy.java | 1 + bundles/org.eclipse.osgi/pom.xml | 2 +- 8 files changed, 43 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF index a21c83f68..ef4703b58 100644 --- a/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Core OSGi Tests Bundle-SymbolicName: org.eclipse.osgi.tests;singleton:=true -Bundle-Version: 3.10.2.qualifier +Bundle-Version: 3.10.3.qualifier Bundle-ClassPath: osgitests.jar Bundle-Vendor: Eclipse.org Bundle-Localization: plugin diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java index 665c8e65e..1a17503c7 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 IBM Corporation and others. + * Copyright (c) 2010, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,8 +10,8 @@ *******************************************************************************/ package geturl; -import java.net.MalformedURLException; -import java.net.URL; +import java.io.IOException; +import java.net.*; import java.security.PrivilegedAction; import java.util.Dictionary; import java.util.Hashtable; @@ -40,8 +40,13 @@ public class Activator implements BundleActivator { throw new RuntimeException("Could not create URL from parts: " + url); } url.toExternalForm(); - return Boolean.TRUE; + try { + url.openConnection(Proxy.NO_PROXY); + } catch (IOException e) { + // expected since our impl throws this + } + return Boolean.TRUE; } }, props); } diff --git a/bundles/org.eclipse.osgi.tests/pom.xml b/bundles/org.eclipse.osgi.tests/pom.xml index 157582ba8..22ed5092c 100644 --- a/bundles/org.eclipse.osgi.tests/pom.xml +++ b/bundles/org.eclipse.osgi.tests/pom.xml @@ -19,7 +19,7 @@ org.eclipse.osgi org.eclipse.osgi.tests - 3.10.2-SNAPSHOT + 3.10.3-SNAPSHOT eclipse-test-plugin diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index d367c4f97..e1c12302d 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -1241,6 +1241,11 @@ public class SystemBundleTests extends AbstractBundleTests { throw new IOException(); } + @Override + public URLConnection openConnection(URL u, Proxy p) throws IOException { + throw new IOException(); + } + } public void testURLMultiplexing01() throws BundleException { diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF index 18d7805cd..57b525df0 100644 --- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF @@ -76,7 +76,7 @@ Bundle-Activator: org.eclipse.osgi.internal.framework.SystemBundleActivator Bundle-Description: %systemBundle Bundle-Copyright: %copyright Bundle-Vendor: %eclipse.org -Bundle-Version: 3.10.2.qualifier +Bundle-Version: 3.10.3.qualifier Bundle-Localization: systembundle Bundle-DocUrl: http://www.eclipse.org Eclipse-ExtensibleAPI: true diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/MultiplexingURLStreamHandler.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/MultiplexingURLStreamHandler.java index e6eff45f3..428f3bac6 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/MultiplexingURLStreamHandler.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/MultiplexingURLStreamHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Cognos Incorporated, IBM Corporation and others. + * Copyright (c) 2006, 2016 Cognos Incorporated, IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,10 +11,12 @@ package org.eclipse.osgi.internal.url; import java.io.IOException; import java.lang.reflect.*; import java.net.*; +import java.net.Proxy; import org.eclipse.osgi.framework.log.FrameworkLogEntry; public class MultiplexingURLStreamHandler extends URLStreamHandler { private static Method openConnectionMethod; + private static Method openConnectionProxyMethod; private static Method equalsMethod; private static Method getDefaultPortMethod; private static Method getHostAddressMethod; @@ -38,6 +40,9 @@ public class MultiplexingURLStreamHandler extends URLStreamHandler { openConnectionMethod = URLStreamHandler.class.getDeclaredMethod("openConnection", new Class[] {URL.class}); //$NON-NLS-1$ openConnectionMethod.setAccessible(true); + openConnectionProxyMethod = URLStreamHandler.class.getDeclaredMethod("openConnection", new Class[] {URL.class, Proxy.class}); //$NON-NLS-1$ + openConnectionProxyMethod.setAccessible(true); + equalsMethod = URLStreamHandler.class.getDeclaredMethod("equals", new Class[] {URL.class, URL.class}); //$NON-NLS-1$ equalsMethod.setAccessible(true); @@ -104,6 +109,24 @@ public class MultiplexingURLStreamHandler extends URLStreamHandler { throw new MalformedURLException(); } + @Override + protected URLConnection openConnection(URL url, Proxy proxy) throws IOException { + URLStreamHandler handler = findAuthorizedURLStreamHandler(protocol); + if (handler != null) { + try { + return (URLConnection) openConnectionProxyMethod.invoke(handler, new Object[] {url, proxy}); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof IOException) + throw (IOException) e.getTargetException(); + throw (RuntimeException) e.getTargetException(); + } catch (Exception e) { + factory.container.getLogServices().log(MultiplexingURLStreamHandler.class.getName(), FrameworkLogEntry.ERROR, "openConnection", e); //$NON-NLS-1$ + throw new RuntimeException(e.getMessage(), e); + } + } + throw new MalformedURLException(); + } + protected boolean equals(URL url1, URL url2) { URLStreamHandler handler = findAuthorizedURLStreamHandler(protocol); if (handler != null) { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/URLStreamHandlerProxy.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/URLStreamHandlerProxy.java index 757f10df9..156605443 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/URLStreamHandlerProxy.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/url/URLStreamHandlerProxy.java @@ -220,6 +220,7 @@ public class URLStreamHandlerProxy extends URLStreamHandler implements ServiceTr protected URLConnection openConnection(URL u, Proxy p) throws IOException { try { Method openConn = realHandlerService.getClass().getMethod("openConnection", new Class[] {URL.class, Proxy.class}); //$NON-NLS-1$ + openConn.setAccessible(true); return (URLConnection) openConn.invoke(realHandlerService, new Object[] {u, p}); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof IOException) diff --git a/bundles/org.eclipse.osgi/pom.xml b/bundles/org.eclipse.osgi/pom.xml index f59c2c660..2152dbeb0 100644 --- a/bundles/org.eclipse.osgi/pom.xml +++ b/bundles/org.eclipse.osgi/pom.xml @@ -19,7 +19,7 @@ org.eclipse.osgi org.eclipse.osgi - 3.10.2-SNAPSHOT + 3.10.3-SNAPSHOT eclipse-plugin -- cgit v1.2.3