From fa9b36803f44b85576b05d708b68277342d22629 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 19 Feb 2009 06:34:03 +0000 Subject: Fix for TUSCANY-2702 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@745752 13f79535-47bb-0310-9956-ffa450edef68 --- .../service/impl/ContributionServiceImpl.java | 47 ++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java index 6471042fed..1c4d8e8547 100644 --- a/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java +++ b/branches/sca-java-1.x/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java @@ -18,10 +18,12 @@ */ package org.apache.tuscany.sca.contribution.service.impl; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLConnection; @@ -304,6 +306,22 @@ public class ContributionServiceImpl implements ContributionService { return contributionMetadata; } + + private static boolean isDirectory(URL url) { + if ("file".equals(url.getProtocol())) { + try { + final URI uri = url.toURI(); + return AccessController.doPrivileged(new PrivilegedAction() { + public Boolean run() { + return new File(uri).isDirectory(); + } + }); + } catch (URISyntaxException e) { + // Ignore + } + } + return false; + } /** * Note: @@ -358,18 +376,23 @@ public class ContributionServiceImpl implements ContributionService { //NOTE: if a contribution is stored on the repository //the stream would be consumed at this point if (storeInRepository || contributionStream == null) { - URLConnection connection = sourceURL.openConnection(); - connection.setUseCaches(false); - // Allow access to open URL stream. Add FilePermission to added to security policy file. - final URLConnection finalConnection = connection; - try { - contributionStream = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public InputStream run() throws IOException { - return finalConnection.getInputStream(); - } - }); - } catch (PrivilegedActionException e) { - throw (IOException)e.getException(); + if (isDirectory(sourceURL)) { + // TUSCANY-2702: This is a directory + contributionStream = null; + } else { + URLConnection connection = sourceURL.openConnection(); + connection.setUseCaches(false); + // Allow access to open URL stream. Add FilePermission to added to security policy file. + final URLConnection finalConnection = connection; + try { + contributionStream = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public InputStream run() throws IOException { + return finalConnection.getInputStream(); + } + }); + } catch (PrivilegedActionException e) { + throw (IOException)e.getException(); + } } try { -- cgit v1.2.3