FileDocCategorySizeDatePackage
Http.javaAPI DocApache Ant 1.703111Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.condition

Http

public class Http extends org.apache.tools.ant.ProjectComponent implements Condition
Condition to wait for a HTTP request to succeed. Its attribute(s) are: url - the URL of the request. errorsBeginAt - number at which errors begin at; default=400.
since
Ant 1.5

Fields Summary
private static final int
ERROR_BEGINS
private String
spec
private int
errorsBeginAt
Constructors Summary
Methods Summary
public booleaneval()

return
true if the HTTP request succeeds
exception
BuildException if an error occurs

        if (spec == null) {
            throw new BuildException("No url specified in http condition");
        }
        log("Checking for " + spec, Project.MSG_VERBOSE);
        try {
            URL url = new URL(spec);
            try {
                URLConnection conn = url.openConnection();
                if (conn instanceof HttpURLConnection) {
                    HttpURLConnection http = (HttpURLConnection) conn;
                    int code = http.getResponseCode();
                    log("Result code for " + spec + " was " + code,
                        Project.MSG_VERBOSE);
                    if (code > 0 && code < errorsBeginAt) {
                        return true;
                    }
                    return false;
                }
            } catch (java.io.IOException e) {
                return false;
            }
        } catch (MalformedURLException e) {
            throw new BuildException("Badly formed URL: " + spec, e);
        }
        return true;
    
public voidsetErrorsBeginAt(int errorsBeginAt)
Set the errorsBeginAt attribute

param
errorsBeginAt number at which errors begin at, default is 400


                                             
        
        this.errorsBeginAt = errorsBeginAt;
    
public voidsetUrl(java.lang.String url)
Set the url attribute

param
url the url of the request


                    
        
        spec = url;