You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2009/07/22 17:17:02 UTC

svn commit: r796762 - in /ant/core/trunk: ./ docs/manual/CoreTasks/ src/etc/testcases/taskdefs/conditions/ src/main/org/apache/tools/ant/taskdefs/condition/ src/tests/junit/org/apache/tools/ant/taskdefs/condition/

Author: bodewig
Date: Wed Jul 22 15:17:00 2009
New Revision: 796762

URL: http://svn.apache.org/viewvc?rev=796762&view=rev
Log:
allow methods other than GET in http condition.  Submitted by Robert Clark.  PR 30244

Added:
    ant/core/trunk/src/etc/testcases/taskdefs/conditions/http.xml   (with props)
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java   (with props)
Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/build.xml
    ant/core/trunk/contributors.xml
    ant/core/trunk/docs/manual/CoreTasks/conditions.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Http.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=796762&r1=796761&r2=796762&view=diff
==============================================================================
Binary files - no diff available.

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=796762&r1=796761&r2=796762&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Jul 22 15:17:00 2009
@@ -800,6 +800,10 @@
    and Ant is running on Java5 or more recent.
    Bugzilla Issue 46752.
 
+ * a new attributes can chose a different request method than GET for
+   the http condition.
+   Bugzilla Report 30244
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/build.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/build.xml?rev=796762&r1=796761&r2=796762&view=diff
==============================================================================
--- ant/core/trunk/build.xml (original)
+++ ant/core/trunk/build.xml Wed Jul 22 15:17:00 2009
@@ -299,6 +299,7 @@
 
   <patternset id="onlinetests">
     <exclude name="**/GetTest.java" if="offline"/>
+    <exclude name="**/HttpTest.java" if="offline"/>
   </patternset>
 
   <patternset id="teststhatfail">

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=796762&r1=796761&r2=796762&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Wed Jul 22 15:17:00 2009
@@ -1014,6 +1014,10 @@
   </name>
   <name>
     <first>Robert</first>
+    <last>Clark</last>
+  </name>
+  <name>
+    <first>Robert</first>
     <last>Flaherty</last>
   </name>
   <name>

Modified: ant/core/trunk/docs/manual/CoreTasks/conditions.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/conditions.html?rev=796762&r1=796761&r2=796762&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/conditions.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/conditions.html Wed Jul 22 15:17:00 2009
@@ -213,6 +213,15 @@
     are detected</td>
     <td align="center">No</td>
   </tr>
+  <tr>
+    <td valign="top">requestMethod</td>
+    <td valign="top">The HTTP method to be used when issuing the request.
+    Any of GET, POST, HEAD, OPTIONS, PUT, DELETEm and TRACE
+    are valid, subject to protocol restrictions. The default if not
+    specified is &quot;GET&quot;.<br/>
+      <em>since Ant 1.8.0</em></td>
+    <td align="center">No</td>
+  </tr>
 </table>
 
 <h4>socket</h4>

Added: ant/core/trunk/src/etc/testcases/taskdefs/conditions/http.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/conditions/http.xml?rev=796762&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/conditions/http.xml (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/conditions/http.xml Wed Jul 22 15:17:00 2009
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project default="nope">
+
+  <target name="nope">
+    <fail>This build file should be run by a testcase</fail>
+  </target>
+
+  <target name="basic-no-method">
+      <condition property="basic-no-method">
+          <http url="http://ant.apache.org/"/>
+      </condition>
+      <condition property="basic-no-method-bad-url">
+          <http url="http://ant.apache.org/this-page-does-not-exist"/>
+      </condition>
+  </target>
+
+  <target name="test-head-request">
+      <condition property="test-head-request">
+          <http url="http://ant.apache.org/" requestMethod="HEAD"/>
+      </condition>
+      <condition property="test-head-request-bad-url">
+          <http url="http://ant.apache.org/this-page-does-not-exist" requestMethod="HEAD"/>
+      </condition>
+  </target>
+
+  <target name="test-get-request">
+      <condition property="test-get-request">
+          <http url="http://ant.apache.org/" requestMethod="GET"/>
+      </condition>
+      <condition property="test-get-request-bad-url">
+          <http url="http://ant.apache.org/this-page-does-not-exist" requestMethod="GET"/>
+      </condition>
+  </target>
+
+  <target name="bad-request-method">
+      <condition property="bad-request-method">
+          <http url="http://ant.apache.org" requestMethod="UNKNOWN"/>
+      </condition>
+  </target>
+
+</project>

Propchange: ant/core/trunk/src/etc/testcases/taskdefs/conditions/http.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Http.java?rev=796762&r1=796761&r2=796762&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Http.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/Http.java Wed Jul 22 15:17:00 2009
@@ -18,6 +18,7 @@
 
 package org.apache.tools.ant.taskdefs.condition;
 
+import java.util.Locale;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -30,11 +31,16 @@
  * 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.
+ *   requestMethod - HTTP request method to use; GET, HEAD, etc. default=GET
  * @since Ant 1.5
  */
 public class Http extends ProjectComponent implements Condition {
     private static final int ERROR_BEGINS = 400;
+    private static final String DEFAULT_REQUEST_METHOD = "GET";
+
     private String spec = null;
+    private String requestMethod = DEFAULT_REQUEST_METHOD;
+
 
     /**
      * Set the url attribute
@@ -56,6 +62,23 @@
     }
 
     /**
+     * Sets the method to be used when issuing the HTTP request.
+     *
+     * @param method The HTTP request method to use. Valid values are
+     *               the same as those accepted by the
+     *               HttpURLConnection.setRequestMetho d() method,
+     *               such as "GET", "HEAD", "TRACE", etc. The default
+     *               if not specified is "GET".
+     *
+     * @see java.net.HttpURLConnection.setRequestMethod()
+     * @since Ant 1.8.0
+     */
+    public void setRequestMethod(String method) {
+        this.requestMethod = method == null ? DEFAULT_REQUEST_METHOD
+            : method.toUpperCase(Locale.US);
+    }
+
+    /**
      * @return true if the HTTP request succeeds
      * @exception BuildException if an error occurs
      */
@@ -70,6 +93,7 @@
                 URLConnection conn = url.openConnection();
                 if (conn instanceof HttpURLConnection) {
                     HttpURLConnection http = (HttpURLConnection) conn;
+                    http.setRequestMethod(requestMethod);
                     int code = http.getResponseCode();
                     log("Result code for " + spec + " was " + code,
                         Project.MSG_VERBOSE);
@@ -78,6 +102,9 @@
                     }
                     return false;
                 }
+            } catch (java.net.ProtocolException pe) {
+                throw new BuildException("Invalid HTTP protocol: "
+                                         + requestMethod, pe);
             } catch (java.io.IOException e) {
                 return false;
             }

Added: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java?rev=796762&view=auto
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java (added)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java Wed Jul 22 15:17:00 2009
@@ -0,0 +1,63 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.condition;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileTest;
+
+/**
+ * Testcases for the &lt;http&gt; condition. All these tests require
+ * us to be online as they attempt to get the status of various pages
+ * on the Ant Apache web site.
+ */
+public class HttpTest extends BuildFileTest {
+
+    public HttpTest(String name) {
+        super(name);
+    }
+
+    /**
+     * The JUnit setup method
+     */
+    public void setUp() {
+        configureProject("src/etc/testcases/taskdefs/conditions/http.xml");
+    }
+
+    public void testNoMethod() {
+       expectPropertySet("basic-no-method", "basic-no-method");
+       assertPropertyUnset("basic-no-method-bad-url");
+    }
+
+    public void testHeadRequest() {
+       expectPropertySet("test-head-request", "test-head-request");
+       assertPropertyUnset("test-head-request-bad-url");
+    }
+
+    public void testGetRequest() {
+       expectPropertySet("test-get-request", "test-get-request");
+       assertPropertyUnset("test-get-request-bad-url");
+    }
+
+    public void testBadRequestMethod() {
+        expectSpecificBuildException("bad-request-method",
+                                     "invalid HTTP request method specified",
+                                     null);
+    }
+
+}

Propchange: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native