You are viewing a plain text version of this content. The canonical link for it is here.
Posted to awf-commits@incubator.apache.org by jm...@apache.org on 2011/08/16 18:13:05 UTC

svn commit: r1158408 - in /incubator/deft/sandbox/src: main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java

Author: jmeehan
Date: Tue Aug 16 18:13:05 2011
New Revision: 1158408

URL: http://svn.apache.org/viewvc?rev=1158408&view=rev
Log:
DEFT-131 - Revert 1154415; Document IAE thrown by public methods.

Modified:
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java?rev=1158408&r1=1158407&r2=1158408&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/http/client/AsynchronousHttpClient.java Tue Aug 16 18:13:05 2011
@@ -58,10 +58,6 @@ public class AsynchronousHttpClient {
     /** The <code>Logger</code>. */
     private static final Logger logger = LoggerFactory.getLogger(AsynchronousHttpClient.class);
 
-    static final int MIN_PORT_NUMBER = 1;
-    static final int MAX_PORT_NUMBER = 65535;
-    static final int DEFAULT_PORT_NUMBER = 80;
-
     private static final long TIMEOUT = 15 * 1000; // 15s
 
     private static final AsyncResult<Response> nopAsyncResult = NopAsyncResult.of(Response.class).nopAsyncResult;
@@ -103,6 +99,9 @@ public class AsynchronousHttpClient {
      * 
      * @param request the definition of the request to make.
      * @param callback the callback to execute when the response is received.
+     * @throws IllegalArgumentException where the <code>URL</code> associated
+     *             with the given <code>Request</code> holds a <code>null</code>
+     *             host or invalid port number.
      */
     public void fetch(final Request request, final AsyncResult<Response> callback) {
         this.request = request;
@@ -116,6 +115,8 @@ public class AsynchronousHttpClient {
      * @param url the URL from which to request, e.g.
      *            <em>http://incubator.apache.org/deft/</em>.
      * @param callback the callback to execute when the response is received.
+     * @throws IllegalArgumentException where the given URL is parsed to a
+     *             <code>null</code> host or with an invalid port number.
      */
     public void get(final String url, final AsyncResult<Response> callback) {
         request = new Request(url, HttpVerb.GET);
@@ -130,6 +131,8 @@ public class AsynchronousHttpClient {
      *            <em>http://incubator.apache.org/deft/</em>.
      * @param body the message body to pass.
      * @param callback the callback to execute when the response is received.
+     * @throws IllegalArgumentException where the given URL is parsed to a
+     *             <code>null</code> host or with an invalid port number.
      */
     public void post(final String url, final String body, final AsyncResult<Response> callback) {
         request = new Request(url, HttpVerb.POST);
@@ -137,6 +140,17 @@ public class AsynchronousHttpClient {
         doFetch(callback, System.currentTimeMillis());
     }
 
+    /**
+     * Make an asynchronous HTTP POST request against the specified URL, and
+     * invoke the given callback when the response upon completion.
+     * 
+     * @param url the URL from which to request, e.g.
+     *            <em>http://incubator.apache.org/deft/</em>.
+     * @param body the message body to pass.
+     * @param callback the callback to execute when the response is received.
+     * @throws IllegalArgumentException where the given URL is parsed to a
+     *             <code>null</code> host or with an invalid port number.
+     */
     public void post(final String url, final byte[] body, final AsyncResult<Response> callback) {
         request = new Request(url, HttpVerb.POST);
         request.setBody(body);
@@ -151,6 +165,8 @@ public class AsynchronousHttpClient {
      *            <em>http://incubator.apache.org/deft/</em>.
      * @param body the message body to pass.
      * @param callback the callback to execute when the response is received.
+     * @throws IllegalArgumentException where the given URL is parsed to a
+     *             <code>null</code> host or with an invalid port number.
      */
     public void put(final String url, final String body, final AsyncResult<Response> callback) {
         request = new Request(url, HttpVerb.PUT);
@@ -176,7 +192,8 @@ public class AsynchronousHttpClient {
         }
 
         responseCallback = callback;
-        int port = getValidPort(request.getURL().getPort());
+        int port = request.getURL().getPort();
+        port = port == -1 ? 80 : port;
 
         startTimeout();
         socket.connect(request.getURL().getHost(), port, new AsyncResult<Boolean>() {
@@ -190,16 +207,6 @@ public class AsynchronousHttpClient {
         });
     }
 
-    protected int getValidPort(int port) {
-
-        if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
-            logger.warn("Port [" + port + "] out of range; returning [" + DEFAULT_PORT_NUMBER + "]");
-            return DEFAULT_PORT_NUMBER;
-        }
-
-        return port;
-    }
-
     /**
      * Close the underlaying {@code AsynchronousSocket}.
      */
@@ -404,5 +411,4 @@ public class AsynchronousHttpClient {
         }
 
     }
-
 }

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java?rev=1158408&r1=1158407&r2=1158408&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/http/client/AsynchronousHttpClientTest.java Tue Aug 16 18:13:05 2011
@@ -19,10 +19,7 @@
  */
 package org.apache.deft.web.http.client;
 
-import static org.apache.deft.web.http.client.AsynchronousHttpClient.DEFAULT_PORT_NUMBER;
 import static org.apache.deft.web.http.client.AsynchronousHttpClient.HTTP_VERSION;
-import static org.apache.deft.web.http.client.AsynchronousHttpClient.MAX_PORT_NUMBER;
-import static org.apache.deft.web.http.client.AsynchronousHttpClient.MIN_PORT_NUMBER;
 import static org.apache.deft.web.http.client.AsynchronousHttpClient.NEWLINE;
 import static org.apache.deft.web.http.client.AsynchronousHttpClient.USER_AGENT_HEADER;
 import static org.junit.Assert.assertEquals;
@@ -105,18 +102,4 @@ public class AsynchronousHttpClientTest 
 
         assertEquals(expected, actual);
     }
-
-    @Test
-    public void testGetValidPort() {
-
-        AsynchronousHttpClient client = new AsynchronousHttpClient();
-
-        assertEquals(MIN_PORT_NUMBER, client.getValidPort(MIN_PORT_NUMBER));
-        assertEquals(DEFAULT_PORT_NUMBER, client.getValidPort(MIN_PORT_NUMBER - 1));
-
-        assertEquals(MAX_PORT_NUMBER, client.getValidPort(MAX_PORT_NUMBER));
-        assertEquals(DEFAULT_PORT_NUMBER, client.getValidPort(MAX_PORT_NUMBER + 1));
-
-        assertEquals(42, client.getValidPort(42));
-    }
 }