Browse Source

bz-63193 Introduce a readTimeout attribute for the "http" condition task

master
Jaikiran Pai 6 years ago
parent
commit
da9ca6ef01
5 changed files with 39 additions and 0 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +5
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +9
    -0
      manual/Tasks/conditions.html
  5. +20
    -0
      src/main/org/apache/tools/ant/taskdefs/condition/Http.java

+ 1
- 0
CONTRIBUTORS View File

@@ -128,6 +128,7 @@ Eduard Wirch
Edwin Woudt
Eli Tucker
Emmanuel Bourg
Eugène Adell
Eric Barboni
Eric Olsen
Eric Pugh


+ 5
- 0
WHATSNEW View File

@@ -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
=====================================



+ 4
- 0
contributors.xml View File

@@ -547,6 +547,10 @@
<first>Emmanuel</first>
<last>Bourg</last>
</name>
<name>
<first>Eugène</first>
<last>Adell</last>
</name>
<name>
<first>Eric</first>
<last>Olsen</last>


+ 9
- 0
manual/Tasks/conditions.html View File

@@ -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>


+ 20
- 0
src/main/org/apache/tools/ant/taskdefs/condition/Http.java View File

@@ -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
@@ -92,6 +95,20 @@ public class Http extends ProjectComponent implements Condition {
followRedirects = f;
}

/**
* 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;
}


Loading…
Cancel
Save