diff options
author | Jaikiran Pai <jaikiran@apache.org> | 2019-02-24 09:38:09 +0530 |
---|---|---|
committer | Jaikiran Pai <jaikiran@apache.org> | 2019-02-24 09:38:09 +0530 |
commit | da9ca6ef0126310ea8d9d36268fe5050941e5325 (patch) | |
tree | 2e00d5dd4327513319a6d6484ddea377e731d023 | |
parent | b5044cad48898a946129258127401a2fc2aa5448 (diff) | |
download | ant-da9ca6ef0126310ea8d9d36268fe5050941e5325.tar.gz |
bz-63193 Introduce a readTimeout attribute for the "http" condition task
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | WHATSNEW | 5 | ||||
-rw-r--r-- | contributors.xml | 4 | ||||
-rw-r--r-- | manual/Tasks/conditions.html | 9 | ||||
-rw-r--r-- | src/main/org/apache/tools/ant/taskdefs/condition/Http.java | 20 |
5 files changed, 39 insertions, 0 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c9a3f0897..56fb51130 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -128,6 +128,7 @@ Eduard Wirch Edwin Woudt Eli Tucker Emmanuel Bourg +Eugène Adell Eric Barboni Eric Olsen Eric Pugh @@ -96,6 +96,11 @@ Other changes: the library behind the sshexec and scp Ant tasks. Github Pull Request #84 + * The "http" condition, now has a "readTimeout" attribute which can be + used to control the amount of time to wait for the read to complete. + Bugzilla Report 63193 + + Changes from Ant 1.10.4 TO Ant 1.10.5 ===================================== diff --git a/contributors.xml b/contributors.xml index 960f2db6f..a8e53ab94 100644 --- a/contributors.xml +++ b/contributors.xml @@ -548,6 +548,10 @@ <last>Bourg</last> </name> <name> + <first>Eugène</first> + <last>Adell</last> + </name> + <name> <first>Eric</first> <last>Olsen</last> </name> diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html index 92799551c..d1d2e4519 100644 --- a/manual/Tasks/conditions.html +++ b/manual/Tasks/conditions.html @@ -215,6 +215,15 @@ URL. By default, HTTP responses errors of 400 or greater are viewed as invalid.< <td>Whether redirects should be followed.<br/><em>since Ant 1.9.7</em></td> <td>No; default is <q>true</q></td> </tr> + <tr> + <td>readTimeout</td> + <td>Read timeout, in milli second, that will be used while reading from the target URL. + Accepts any value >= 0. Value of 0 implies wait indefinitely. Value < 0 will be silently + ignored.<br/> + <em>since Ant 1.10.6</em></td> + </td> + <td>No; defaults to <q>0</q></td> + </tr> </table> <h4 id="socket">socket</h4> diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Http.java b/src/main/org/apache/tools/ant/taskdefs/condition/Http.java index de9317475..7ce6aa129 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/Http.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/Http.java @@ -24,6 +24,7 @@ import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; +import java.net.SocketTimeoutException; import java.util.Locale; import org.apache.tools.ant.BuildException; @@ -35,6 +36,7 @@ import org.apache.tools.ant.ProjectComponent; * url - the URL of the request. * errorsBeginAt - number at which errors begin at; default=400. * requestMethod - HTTP request method to use; GET, HEAD, etc. default=GET + * readTimeout - The read timeout in ms. default=0 * @since Ant 1.5 */ public class Http extends ProjectComponent implements Condition { @@ -46,6 +48,7 @@ public class Http extends ProjectComponent implements Condition { private boolean followRedirects = true; private int errorsBeginAt = ERROR_BEGINS; + private int readTimeout = 0; /** * Set the url attribute @@ -93,6 +96,20 @@ public class Http extends ProjectComponent implements Condition { } /** + * Sets the read timeout. Any value < 0 will be ignored + * + * @param t the timeout value in milli seconds + * + * @see java.net.HttpURLConnection#setReadTimeout + * @since Ant 1.10.6 + */ + public void setReadTimeout(int t) { + if(t >= 0) { + this.readTimeout = t; + } + } + + /** * @return true if the HTTP request succeeds * @exception BuildException if an error occurs */ @@ -110,6 +127,7 @@ public class Http extends ProjectComponent implements Condition { HttpURLConnection http = (HttpURLConnection) conn; http.setRequestMethod(requestMethod); http.setInstanceFollowRedirects(followRedirects); + http.setReadTimeout(readTimeout); int code = http.getResponseCode(); log("Result code for " + spec + " was " + code, Project.MSG_VERBOSE); @@ -118,6 +136,8 @@ public class Http extends ProjectComponent implements Condition { } catch (ProtocolException pe) { throw new BuildException("Invalid HTTP protocol: " + requestMethod, pe); + } catch (SocketTimeoutException ste) { + return false; } catch (IOException e) { return false; } |