mirror of https://github.com/apache/ant-ivy
add disconnect on http connection when connection is not needed any more (thanks to andreas ronge)
git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
034a32ac32
commit
cc87a94db5
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue