diff --git a/src/java/fr/jayasoft/ivy/ResolvedURL.java b/src/java/fr/jayasoft/ivy/ResolvedURL.java index 5c435da9..35982727 100644 --- a/src/java/fr/jayasoft/ivy/ResolvedURL.java +++ b/src/java/fr/jayasoft/ivy/ResolvedURL.java @@ -6,6 +6,7 @@ package fr.jayasoft.ivy; import java.io.IOException; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -31,12 +32,17 @@ public class ResolvedURL implements ArtifactInfo { public long getLastModified() { if (_lastModified == null) { + URLConnection con = null; try { - URLConnection con = url.openConnection(); + con = url.openConnection(); _lastModified = new Long(con.getLastModified()); } catch (IOException e) { Message.warn("impossible to open connection to "+url+": "+e.getMessage()); _lastModified = new Long(0); + } finally { + if (con instanceof HttpURLConnection) { + ((HttpURLConnection)con).disconnect(); + } } } return _lastModified.longValue(); diff --git a/src/java/fr/jayasoft/ivy/repository/url/URLResource.java b/src/java/fr/jayasoft/ivy/repository/url/URLResource.java index ff0a8d56..c80ea993 100644 --- a/src/java/fr/jayasoft/ivy/repository/url/URLResource.java +++ b/src/java/fr/jayasoft/ivy/repository/url/URLResource.java @@ -7,6 +7,7 @@ package fr.jayasoft.ivy.repository.url; import java.io.IOException; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -37,18 +38,23 @@ public class URLResource implements Resource { } private void init() { + URLConnection con = null; try { _lastModified = 0; _contentLength = 0; _exists = URLHandlerRegistry.getDefault().isReachable(_url); if (_exists) { - URLConnection con = _url.openConnection(); + con = _url.openConnection(); _lastModified = con.getLastModified(); _contentLength = con.getContentLength(); } } catch (IOException e) { Message.verbose("impossible to open connection to "+_url+":"+e.getMessage()); _exists = false; + } finally { + if (con instanceof HttpURLConnection) { + ((HttpURLConnection)con).disconnect(); + } } _init = true; } diff --git a/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java b/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java index 18902f9a..378d8715 100644 --- a/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java +++ b/src/java/fr/jayasoft/ivy/resolver/ResolverHelper.java @@ -85,17 +85,22 @@ public class ResolverHelper { String fileSep = rep.getFileSeparator(); Message.debug("\tusing "+rep+" to list all in "+parent); List all = rep.list(parent); - Message.debug("\t\tfound "+all.size()+" resources"); - List names = new ArrayList(all.size()); - for (Iterator iter = all.iterator(); iter.hasNext();) { - String path = (String)iter.next(); - if (path.endsWith(fileSep)) { - path = path.substring(0, path.length() - 1); + if (all != null) { + Message.debug("\t\tfound "+all.size()+" resources"); + List names = new ArrayList(all.size()); + for (Iterator iter = all.iterator(); iter.hasNext();) { + String path = (String)iter.next(); + if (path.endsWith(fileSep)) { + path = path.substring(0, path.length() - 1); + } + int slashIndex = path.lastIndexOf(fileSep); + names.add(path.substring(slashIndex +1)); } - int slashIndex = path.lastIndexOf(fileSep); - names.add(path.substring(slashIndex +1)); + return (String[])names.toArray(new String[names.size()]); + } else { + Message.debug("\t\tno resources found"); + return null; } - return (String[])names.toArray(new String[names.size()]); } catch (Exception e) { Message.warn("problem while listing resources in "+parent+" with "+rep+": "+e.getClass()+" "+e.getMessage()); return null; diff --git a/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java b/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java index 0ea30a67..d2255c9d 100644 --- a/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java +++ b/src/java/fr/jayasoft/ivy/url/BasicURLHandler.java @@ -30,8 +30,9 @@ public class BasicURLHandler implements URLHandler { return isReachable(url, 0); } public boolean isReachable(URL url, int timeout) { + URLConnection con = null; try { - URLConnection con = url.openConnection(); + con = url.openConnection(); if (con instanceof HttpURLConnection) { int status = ((HttpURLConnection)con).getResponseCode(); if (status == HttpStatus.SC_OK) { @@ -54,6 +55,10 @@ public class BasicURLHandler implements URLHandler { Message.info("You probably access the destination server through a proxy server that is not well configured."); } catch (IOException e) { Message.error("Server access Error: "+e.getMessage()+" url="+url); + } finally { + if (con instanceof HttpURLConnection) { + ((HttpURLConnection)con).disconnect(); + } } return false; }