incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1240017 - /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java
Date Fri, 03 Feb 2012 07:17:44 GMT
Author: cziegeler
Date: Fri Feb  3 07:17:44 2012
New Revision: 1240017

URL: http://svn.apache.org/viewvc?rev=1240017&view=rev
Log:
SLING-2400 : Resource URI hint should be checked before it is used

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java?rev=1240017&r1=1240016&r2=1240017&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InternalResource.java
Fri Feb  3 07:17:44 2012
@@ -22,6 +22,7 @@ import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -69,6 +70,26 @@ public class InternalResource extends In
                                     && resource.getDigest() != null
                                     && resource.getDigest().length() > 0) ?
                               (String)dict.get(InstallableResource.RESOURCE_URI_HINT) : null;
+        // check if resourceUri is accessible
+        boolean useResourceUri = resourceUri != null;
+        if ( resourceUri != null ) {
+            InputStream resourceUriIS = null;
+            try {
+                final URI uri = new URI(resourceUri);
+                resourceUriIS = uri.toURL().openStream();
+                // everything fine
+            } catch (final Exception use) {
+                useResourceUri = false;
+            } finally {
+                if ( resourceUriIS != null ) {
+                    try {
+                        resourceUriIS.close();
+                    } catch (final IOException ignore) {
+                        // ignore
+                    }
+                }
+            }
+        }
 
         if ( is != null &&
              (InstallableResource.TYPE_PROPERTIES.equals(type) ||
@@ -89,7 +110,7 @@ public class InternalResource extends In
             digest = FileDataStore.computeDigest(dict);
         } else {
             type = (type != null ? type : InstallableResource.TYPE_FILE);
-            if ( resourceUri != null ) {
+            if ( resourceUri != null && useResourceUri ) {
                 digest = resource.getDigest();
             } else {
                 final String url = scheme + ':' + resource.getId();
@@ -114,7 +135,7 @@ public class InternalResource extends In
                 digest,
                 resource.getPriority(),
                 dataFile,
-                resourceUri);
+                useResourceUri ? resourceUri : null);
     }
 
     /** The unique resource url. */



Mime
View raw message