You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2020/09/10 08:02:34 UTC

[felix-dev] branch master updated: FELIX-6326: don't encode resource urls but handle query and refs directly.

This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 810b56a  FELIX-6326: don't encode resource urls but handle query and refs directly.
810b56a is described below

commit 810b56a1b86f112eaabde9d187f5f0ca41e31cb9
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Thu Sep 10 09:50:02 2020 +0200

    FELIX-6326: don't encode resource urls but handle query and refs directly.
---
 .../apache/felix/framework/BundleRevisionImpl.java | 29 ++++++++--------------
 .../framework/URLHandlersBundleURLConnection.java  | 15 +++--------
 .../felix/framework/ResourceLoadingTest.java       |  8 ++++++
 3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
index 8b99853..036732b 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
@@ -18,6 +18,16 @@
  */
 package org.apache.felix.framework;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.felix.framework.cache.Content;
 import org.apache.felix.framework.util.FelixConstants;
 import org.apache.felix.framework.util.MultiReleaseContent;
@@ -36,17 +46,6 @@ import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
 import org.osgi.resource.Resource;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-
 public class BundleRevisionImpl implements BundleRevision, Resource
 {
     public final static int EAGER_ACTIVATION = 0;
@@ -642,14 +641,6 @@ public class BundleRevisionImpl implements BundleRevision, Resource
 
         try
         {
-            path = new URI(FelixConstants.BUNDLE_URL_PROTOCOL,
-                null,
-                m_bundle.getFramework()._getProperty(Constants.FRAMEWORK_UUID),
-                port,
-                path,
-                null,
-                null).getRawPath();
-
             return m_secureAction.createURL(null,
                 FelixConstants.BUNDLE_URL_PROTOCOL + "://" +
                 m_bundle.getFramework()._getProperty(Constants.FRAMEWORK_UUID) + "_" + m_id + ":" + port + path,
diff --git a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
index f2927ad..794af28 100644
--- a/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
+++ b/framework/src/main/java/org/apache/felix/framework/URLHandlersBundleURLConnection.java
@@ -20,8 +20,6 @@ package org.apache.felix.framework;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.Permission;
@@ -48,19 +46,14 @@ class URLHandlersBundleURLConnection extends URLConnection
     {
         super(url);
 
+        String urlString = url.toExternalForm();
+
+        m_path = urlString.substring(urlString.indexOf(url.getPath()));
+
         // If this is an attempt to create a connection to the root of
         // the bundle, then throw an exception since this isn't possible.
         // We only allow "/" as a valid URL so it can be used as context
         // for creating other URLs.
-        try
-        {
-            m_path = new URI(url.getProtocol() + "://felix" + url.getPath()).getPath();
-        }
-        catch (URISyntaxException e)
-        {
-            throw new IOException(e);
-        }
-
         if ((m_path == null) || (m_path.length() == 0) || m_path.equals("/"))
         {
             throw new IOException("Resource does not exist: " + url);
diff --git a/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java b/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java
index c9db286..ce1167c 100644
--- a/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java
+++ b/framework/src/test/java/org/apache/felix/framework/ResourceLoadingTest.java
@@ -24,6 +24,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.jar.JarOutputStream;
@@ -114,6 +115,13 @@ public class ResourceLoadingTest extends TestCase
 
         reader = new BufferedReader(new InputStreamReader(testBundle.adapt(BundleWiring.class).getClassLoader().getResource(name).openStream()));
         assertEquals("This is a Test", reader.readLine());
+
+        URL url = testBundle.adapt(BundleWiring.class).getClassLoader().getResource(name);
+
+        URL testURL = new URL(url.getProtocol() + "://" +  url.getHost() + ":" +  url.getPort() + "/" + name);
+
+        reader = new BufferedReader(new InputStreamReader(testURL.openStream()));
+        assertEquals("This is a Test", reader.readLine());
     }
 
     private static void deleteDir(File root) throws IOException