[FELIX-1994]improve fix to handle more generic case

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@904011 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/webconsole/admin/src/main/java/org/apache/felix/karaf/webconsole/admin/AdminPlugin.java b/karaf/webconsole/admin/src/main/java/org/apache/felix/karaf/webconsole/admin/AdminPlugin.java
index cd2d3c7..db54122 100644
--- a/karaf/webconsole/admin/src/main/java/org/apache/felix/karaf/webconsole/admin/AdminPlugin.java
+++ b/karaf/webconsole/admin/src/main/java/org/apache/felix/karaf/webconsole/admin/AdminPlugin.java
@@ -174,24 +174,28 @@
 
     protected URL getResource(String path) {
         path = path.substring(NAME.length() + 1);
-        if (path.length() == 0) {
-            //it means input parameter path is just plugin name like /admin but not real resource path.
-            //on felix the return url would be null in this case, which is correct expected behavior.
-            //but on equinox the return url is like bundleresource://184.fwk1674485910/,
-            //which cause NPE in AbstractWebConsolePlugin.spoolResource
-            //so just return null ensure it works both with felix and equinox
-            return null;
-        }
-
         URL url = this.classLoader.getResource(path);
-        try {
-            InputStream ins = url.openStream();
-            if (ins == null) {
-                this.log.error("failed to open " + url);
+        if (url != null) {
+            InputStream ins = null;
+            try {
+                ins = url.openStream();
+                if (ins == null) {
+                    this.log.error("failed to open " + url);
+                    url = null;
+                }
+            } catch (IOException e) {
+                this.log.error(e.getMessage(), e);
+                url = null;
+            } finally {
+                if (ins != null) {
+                    try {
+                        ins.close();
+                    } catch (IOException e) {
+                        this.log.error(e.getMessage(), e);
+                    }
+                }
             }
-        } catch (IOException e) {
-            this.log.error(e.getMessage(), e);
-        }
+        } 
         return url;
     }
 
diff --git a/karaf/webconsole/features/src/main/java/org/apache/felix/karaf/webconsole/features/FeaturesPlugin.java b/karaf/webconsole/features/src/main/java/org/apache/felix/karaf/webconsole/features/FeaturesPlugin.java
index 4036b52..a68f44f 100644
--- a/karaf/webconsole/features/src/main/java/org/apache/felix/karaf/webconsole/features/FeaturesPlugin.java
+++ b/karaf/webconsole/features/src/main/java/org/apache/felix/karaf/webconsole/features/FeaturesPlugin.java
@@ -195,28 +195,29 @@
     protected URL getResource( String path )
     {
         path = path.substring( NAME.length() + 1 );
-        if (path.length() == 0) {
-            //it means input parameter path is just plugin name like /features but not real resource path.
-            //on felix the return url would be null in this case, which is correct expected behavior.
-            //but on equinox the return url is like bundleresource://184.fwk1674485910/,
-            //which cause NPE in AbstractWebConsolePlugin.spoolResource
-            //so just return null ensure it works both with felix and equinox
-            return null;
-        }
-
         URL url = this.classLoader.getResource( path );
-        try
-        {
-            InputStream ins = url.openStream();
-            if ( ins == null )
-            {
-                this.log.error( "failed to open " + url );
+        if (url != null) {
+            InputStream ins = null;
+            try {
+                ins = url.openStream();
+                if (ins == null) {
+                    this.log.error("failed to open " + url);
+                    url = null;
+                }
+            } catch (IOException e) {
+                this.log.error(e.getMessage(), e);
+                url = null;
+            } finally {
+                if (ins != null) {
+                    try {
+                        ins.close();
+                    } catch (IOException e) {
+                        this.log.error(e.getMessage(), e);
+                    }
+                }
             }
         }
-        catch ( IOException e )
-        {
-            this.log.error( e.getMessage(), e );
-        }
+
         return url;
     }
 
diff --git a/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java b/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java
index 8f2f3ec..1d72c71 100644
--- a/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java
+++ b/karaf/webconsole/gogo/src/main/java/org/apache/felix/karaf/webconsole/gogo/GogoPlugin.java
@@ -135,28 +135,28 @@
     protected URL getResource( String path )
     {
         path = path.substring( NAME.length() + 1 );
-        if (path.length() == 0) {
-            //it means input parameter path is just plugin name like /gogo but not real resource path.
-            //on felix the return url would be null in this case, which is correct expected behavior.
-            //but on equinox the return url is like bundleresource://184.fwk1674485910/,
-            //which cause NPE in AbstractWebConsolePlugin.spoolResource
-            //so just return null ensure it works both with felix and equinox
-            return null;
-        }
-
         URL url = this.getClass().getClassLoader().getResource( path );
-        try
-        {
-            InputStream ins = url.openStream();
-            if ( ins == null )
-            {
-                this.log.error( "failed to open " + url );
+        if (url != null) {
+            InputStream ins = null;
+            try {
+                ins = url.openStream();
+                if (ins == null) {
+                    this.log.error("failed to open " + url);
+                    url = null;
+                }
+            } catch (IOException e) {
+                this.log.error(e.getMessage(), e);
+                url = null;
+            } finally {
+                if (ins != null) {
+                    try {
+                        ins.close();
+                    } catch (IOException e) {
+                        this.log.error(e.getMessage(), e);
+                    }
+                }
             }
         }
-        catch ( IOException e )
-        {
-            this.log.error( e.getMessage(), e );
-        }
         return url;
     }