Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 176 invoked from network); 21 Sep 2006 04:04:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Sep 2006 04:04:38 -0000 Received: (qmail 12747 invoked by uid 500); 21 Sep 2006 04:04:37 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 12705 invoked by uid 500); 21 Sep 2006 04:04:37 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 12693 invoked by uid 500); 21 Sep 2006 04:04:37 -0000 Received: (qmail 12690 invoked by uid 99); 21 Sep 2006 04:04:37 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Sep 2006 21:04:36 -0700 Authentication-Results: idunn.apache.osuosl.org smtp.mail=antoine@apache.org; spf=permerror X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME Received-SPF: error (idunn.apache.osuosl.org: domain apache.org from 140.211.166.113 cause and error) Received: from [140.211.166.113] ([140.211.166.113:50416] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 8A/1B-04092-35F02154 for ; Wed, 20 Sep 2006 21:04:35 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id BDAA81A9823; Wed, 20 Sep 2006 21:04:33 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r448452 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW contributors.xml src/etc/testcases/types/resources/build.xml src/main/org/apache/tools/ant/types/resources/URLResource.java Date: Thu, 21 Sep 2006 04:04:33 -0000 To: ant-cvs@apache.org From: antoine@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060921040433.BDAA81A9823@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: antoine Date: Wed Sep 20 21:04:32 2006 New Revision: 448452 URL: http://svn.apache.org/viewvc?view=rev&rev=448452 Log: patch submitted by Xavier Hanin, mainly closing HttpURLConnection Modified: ant/core/trunk/CONTRIBUTORS ant/core/trunk/WHATSNEW ant/core/trunk/contributors.xml ant/core/trunk/src/etc/testcases/types/resources/build.xml ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java Modified: ant/core/trunk/CONTRIBUTORS URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?view=diff&rev=448452&r1=448451&r2=448452 ============================================================================== Binary files - no diff available. Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=448452&r1=448451&r2=448452 ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Wed Sep 20 21:04:32 2006 @@ -20,7 +20,7 @@ * the ant wrapper script should now correctly locate the java executable in more recent IBM JDKs for AIX as well. -* URLResource did not close jar files. +* URLResource did not close jar files, and also did not disconnect HTTPConnection (s). * created junitvmwatcher*.properties files but did not close and delete them. Modified: ant/core/trunk/contributors.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?view=diff&rev=448452&r1=448451&r2=448452 ============================================================================== --- ant/core/trunk/contributors.xml (original) +++ ant/core/trunk/contributors.xml Wed Sep 20 21:04:32 2006 @@ -1016,6 +1016,10 @@ Xavier + Hanin + + + Xavier Witdouck Modified: ant/core/trunk/src/etc/testcases/types/resources/build.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/types/resources/build.xml?view=diff&rev=448452&r1=448451&r2=448452 ============================================================================== --- ant/core/trunk/src/etc/testcases/types/resources/build.xml (original) +++ ant/core/trunk/src/etc/testcases/types/resources/build.xml Wed Sep 20 21:04:32 2006 @@ -320,7 +320,10 @@ - + + + + Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java?view=diff&rev=448452&r1=448451&r2=448452 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/URLResource.java Wed Sep 20 21:04:32 2006 @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.net.MalformedURLException; @@ -148,6 +149,28 @@ if (isReference()) { return ((Resource) getCheckedRef()).isExists(); } + return isExists(false); + } + + /** + * Find out whether the URL exists, and close the connection + * opened to the URL if closeConnection is true. + * + * Note that this method does ensure that if: + * - the resource exists (if it returns true) + * - and if the current object is not a reference + * (isReference() returns false) + * - and if it was called with closeConnection to false, + * + * then the connection to the URL (stored in the conn + * private field) will be opened, and require to be closed + * by the caller. + * + * @param closeConnection true if the connection should be closed + * after the call, false if it should stay open. + * @return true if this resource exists. + */ + private synchronized boolean isExists(boolean closeConnection) { if (getURL() == null) { return false; } @@ -156,9 +179,14 @@ return true; } catch (IOException e) { return false; + } finally { + if (closeConnection) { + close(); + } } } + /** * Tells the modification time in milliseconds since 01.01.1970 . * @@ -169,15 +197,10 @@ if (isReference()) { return ((Resource) getCheckedRef()).getLastModified(); } - if (!isExists()) { - return 0L; - } - try { - connect(); - return conn.getLastModified(); - } catch (IOException e) { + if (!isExists(false)) { return 0L; } + return conn.getLastModified(); } /** @@ -199,7 +222,7 @@ if (isReference()) { return ((Resource) getCheckedRef()).getSize(); } - if (!isExists()) { + if (!isExists(false)) { return 0L; } try { @@ -271,6 +294,7 @@ * Resource as a stream. * @throws UnsupportedOperationException if OutputStreams are not * supported for this Resource type. + * @throws IOException if the URL cannot be opened. */ public synchronized OutputStream getOutputStream() throws IOException { if (isReference()) { @@ -286,6 +310,7 @@ /** * Ensure that we have a connection. + * @throws IOException if the connection cannot be established. */ protected synchronized void connect() throws IOException { URL u = getURL(); @@ -304,7 +329,15 @@ } } - private void close() { + /** + * Closes the URL connection if: + * - it is opened (i.e. the field conn is not null) + * - this type of URLConnection supports some sort of close mechanism + * + * This method ensures the field conn will be null after the call. + * + */ + private synchronized void close() { if (conn != null) { try { if (conn instanceof JarURLConnection) { @@ -312,9 +345,11 @@ JarFile jf = juc.getJarFile(); jf.close(); jf = null; + } else if (conn instanceof HttpURLConnection) { + ((HttpURLConnection) conn).disconnect(); } } catch (IOException exc) { - + //ignore } finally { conn = null; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org