ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1531911 - /ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/NetUtils.java
Date Mon, 14 Oct 2013 14:32:20 GMT
Author: jawi
Date: Mon Oct 14 14:32:19 2013
New Revision: 1531911

URL: http://svn.apache.org/r1531911
Log:
Added convenience method for directly checking a String-representation of an URL.

Modified:
    ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/NetUtils.java

Modified: ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/NetUtils.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/NetUtils.java?rev=1531911&r1=1531910&r2=1531911&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/NetUtils.java (original)
+++ ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/NetUtils.java Mon Oct 14 14:32:19
2013
@@ -20,6 +20,7 @@ package org.apache.ace.test.utils;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
 import java.net.URL;
 
 /**
@@ -30,12 +31,36 @@ public class NetUtils {
     /**
      * Waits for a HTTP URL to become 'available', will retry every 100 milliseconds until
it is available or timeout
      * has been exceeded. Available in this context means the specified status code is returned
when accessing the URL.
-     *
-     * @param url HTTP URL that should be tested for availability.
-     * @param responseCode The response code to be expected on the specified URL when it
is available.
-     * @param timeout Amount of milliseconds to keep trying to access the URL.
-     * @return True if the response of the URL has the specified status code within the specified
timeout delay, false otherwise.
-     * @throws IllegalArgumentException If the specified URL does not use the HTTP protocol.
+     * 
+     * @param url
+     *            HTTP URL that should be tested for availability.
+     * @param responseCode
+     *            The response code to be expected on the specified URL when it is available.
+     * @param timeout
+     *            Amount of milliseconds to keep trying to access the URL.
+     * @return True if the response of the URL has the specified status code within the specified
timeout delay, false
+     *         otherwise.
+     * @throws IllegalArgumentException
+     *             If the specified URL does not use the HTTP protocol.
+     */
+    public static boolean waitForURL(String url, int responseCode, int timeout) throws MalformedURLException
{
+        return waitForURL(new URL(url), responseCode, timeout);
+    }
+
+    /**
+     * Waits for a HTTP URL to become 'available', will retry every 100 milliseconds until
it is available or timeout
+     * has been exceeded. Available in this context means the specified status code is returned
when accessing the URL.
+     * 
+     * @param url
+     *            HTTP URL that should be tested for availability.
+     * @param responseCode
+     *            The response code to be expected on the specified URL when it is available.
+     * @param timeout
+     *            Amount of milliseconds to keep trying to access the URL.
+     * @return True if the response of the URL has the specified status code within the specified
timeout delay, false
+     *         otherwise.
+     * @throws IllegalArgumentException
+     *             If the specified URL does not use the HTTP protocol.
      */
     public static boolean waitForURL(URL url, int responseCode, int timeout) {
         long deadline = System.currentTimeMillis() + timeout;
@@ -46,7 +71,8 @@ public class NetUtils {
                 if (connection.getResponseCode() == responseCode) {
                     return true;
                 }
-            } catch (ClassCastException cce) {
+            }
+            catch (ClassCastException cce) {
                 throw new IllegalArgumentException("Expected url to be an HTTP url, not:
" + url.toString(), cce);
             }
             catch (IOException ioe) {



Mime
View raw message