geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r573094 - in /geronimo/sandbox/AsyncHttpClient/src: main/java/org/apache/ahc/ main/java/org/apache/ahc/codec/ test/catalina/webapps/ROOT/ test/java/org/apache/ahc/
Date Wed, 05 Sep 2007 23:10:03 GMT
Author: jgenender
Date: Wed Sep  5 16:09:57 2007
New Revision: 573094

URL: http://svn.apache.org/viewvc?rev=573094&view=rev
Log:
Added request timeout

Added:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
      - copied, changed from r573031, geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/HttpIoHandler.java
    geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/timeout.jsp
    geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java
Removed:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/HttpIoHandler.java
Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AHCCallback.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java
    geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java
    geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AHCCallback.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AHCCallback.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AHCCallback.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AHCCallback.java Wed Sep
 5 16:09:57 2007
@@ -25,4 +25,5 @@
     public void onResponse(HttpResponseMessage message);
     public void onException(Throwable cause);
     public void onClosed();
+    public void onTimeout();
 }

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java Wed
Sep  5 16:09:57 2007
@@ -28,6 +28,8 @@
 import org.apache.ahc.ssl.TrustManagerFactoryImpl;
 import org.apache.ahc.codec.HttpRequestMessage;
 import org.apache.ahc.codec.HttpProtocolCodecFactory;
+import org.apache.ahc.codec.HttpIoHandler;
+import org.apache.ahc.util.AsyncHttpClientException;
 
 import javax.net.ssl.SSLContext;
 import java.net.URL;
@@ -37,27 +39,38 @@
 
 public class AsyncHttpClient {
 
-    public static int DEFAULT_CONNECTION_TIMEOUT = 30;
+    public static int DEFAULT_REQUEST_TIMEOUT = 30000;
+    public static int DEFAULT_CONNECTION_TIMEOUT = 30000;
     public static String DEFAULT_SSL_PROTOCOL = "TLS";
 
     private URL url;
-    private boolean followRedirects = true;
     private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
     private String sslProtocol = DEFAULT_SSL_PROTOCOL;
     private SocketConnector connector;
     private IoSession session;
     private AHCCallback callback;
+    private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
 
     public AsyncHttpClient(URL url, AHCCallback callback) {
+        this(url, callback,DEFAULT_CONNECTION_TIMEOUT, DEFAULT_REQUEST_TIMEOUT);
+    }
+
+    public AsyncHttpClient(URL url, AHCCallback callback, int connectionTimeout) {
+        this(url, callback, connectionTimeout, DEFAULT_REQUEST_TIMEOUT);
+    }
+
+    public AsyncHttpClient(URL url, AHCCallback callback, int connectionTimeout, int requestTimeout)
{
         this.url = url;
         this.callback = callback;
+        this.connectionTimeout = connectionTimeout;
+        this.requestTimeout = requestTimeout;
     }
 
     public void connect() throws Exception {
         SocketConnector connector = new SocketConnector();
         IoConnectorConfig cfg = connector.getDefaultConfig();
 
-        cfg.setConnectTimeout(connectionTimeout);
+        cfg.setConnectTimeout(connectionTimeout/1000);
 
         String scheme = url.getProtocol();
         int port = url.getPort();
@@ -75,7 +88,7 @@
 
         cfg.getFilterChain().addLast("protocolFilter",new ProtocolCodecFilter( new HttpProtocolCodecFactory(url)));
 
-        ConnectFuture future = connector.connect(new InetSocketAddress(url.getHost(), port),
new HttpIoHandler(callback));
+        ConnectFuture future = connector.connect(new InetSocketAddress(url.getHost(), port),
new HttpIoHandler(callback, requestTimeout));
         future.join();
         if (!future.isConnected()) {
             throw new IOException("Cannot connect to " + url.toString());
@@ -91,6 +104,10 @@
     }
 
     public void sendRequest(HttpRequestMessage message){
+        if (session == null || !session.isConnected()){
+            callback.onException(new AsyncHttpClientException("Objectdoes not have a valid
connection to a server."));
+            return;
+        }
         session.write(message);
     }
 
@@ -100,14 +117,6 @@
 
     public void setConnectionTimeout(int connectionTimeout) {
         this.connectionTimeout = connectionTimeout;
-    }
-
-    public boolean isFollowRedirects() {
-        return followRedirects;
-    }
-
-    public void setFollowRedirects(boolean followRedirects) {
-        this.followRedirects = followRedirects;
     }
 
     public String getSslProtocol() {

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java Wed
Sep  5 16:09:57 2007
@@ -50,6 +50,8 @@
     public final static String COOKIE_VERSION = "version";
 
     public final static String SET_COOKIE = "Set-Cookie";
+    public final static String CONNECTION = "Connection";
+    public final static String LOCATION = "Location";
     public final static String TRANSFER_ENCODING = "Transfer-Encoding";
     public final static String CHUNKED = "chunked";
 
@@ -117,6 +119,14 @@
 
         if (name.equalsIgnoreCase(HttpMessage.CONTENT_LENGTH)) {
             msg.setContentLength(Integer.parseInt(value));
+        }
+
+        if (name.equalsIgnoreCase(CONNECTION)) {
+            msg.setConnection(value);
+        }
+
+        if (name.equalsIgnoreCase(LOCATION)) {
+            msg.setLocation(value);
         }
 
         if (name.equalsIgnoreCase(TRANSFER_ENCODING) && value != null &&
value.equalsIgnoreCase(CHUNKED)) {

Copied: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
(from r573031, geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/HttpIoHandler.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java?p2=geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java&p1=geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/HttpIoHandler.java&r1=573031&r2=573094&rev=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/HttpIoHandler.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
Wed Sep  5 16:09:57 2007
@@ -17,40 +17,124 @@
  *  under the License.
  *
  */
-package org.apache.ahc;
+package org.apache.ahc.codec;
 
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
-import org.apache.ahc.codec.HttpResponseMessage;
-import org.apache.ahc.codec.HttpResponseDecoder;
+import org.apache.ahc.AHCCallback;
+
+import java.util.LinkedList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledFuture;
 
 public class HttpIoHandler extends IoHandlerAdapter {
-    private AHCCallback callback;
 
+    public final static int DEFAULT_THREAD_POOL_SIZE = 10;
+    public final static String CONNECTION_CLOSE = "close";
 
-    public HttpIoHandler(AHCCallback callback) {
+    private AHCCallback callback;
+    private List<HttpRequestMessage> sentQueue = Collections.synchronizedList(new LinkedList<HttpRequestMessage>());
+    private ScheduledThreadPoolExecutor scheduler = null;
+    private int timeoutDelay;
+
+    public HttpIoHandler(AHCCallback callback, int timeoutDelay) {
         this.callback = callback;
+        this.timeoutDelay = timeoutDelay;
     }
 
     public void sessionOpened(IoSession ioSession) throws Exception {
-        super.sessionOpened(ioSession);
+        if (timeoutDelay > 0) {
+            scheduler = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(DEFAULT_THREAD_POOL_SIZE);
+
+            //Install the schedule purger to purge any cancelled tasks
+            //to prevent memory leaks
+            scheduler.scheduleWithFixedDelay(new SchedulePurger(), 5000, 5000, TimeUnit.MILLISECONDS);
+        }
     }
 
     public void messageReceived(IoSession ioSession, Object object) throws Exception {
-        HttpResponseMessage message = (HttpResponseMessage)object;
-        callback.onResponse(message);
+        //For each send, we should have a response
+        HttpResponseMessage response = (HttpResponseMessage) object;
+        //Remove the sent message
+        HttpRequestMessage request = sentQueue.remove(0);
+        ScheduledFuture handle = request.getTimeoutHandle();
+        if (handle != null) {
+
+            boolean canceled = handle.cancel(true);
+            //See if it canceled
+            if (!canceled) {
+                //Couldn't cancel it and it ran, so too late :-(
+                return;
+            }
+        }
+        callback.onResponse(response);
+        if (response.getConnection() != null && response.getConnection().equalsIgnoreCase(CONNECTION_CLOSE))
{
+            ioSession.close();
+        }
     }
 
     public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception
{
         //Clean up if any in-proccess decoding was occurring
         ioSession.removeAttribute(HttpResponseDecoder.CURRENT_RESPONSE);
+        if (timeoutDelay > 0) {
+            sentQueue.clear();
+        }
         callback.onException(throwable);
+        //Exception is bad, so just close it up
+        ioSession.close();
     }
 
-
     public void sessionClosed(IoSession ioSession) throws Exception {
         //Clean up if any in-proccess decoding was occurring
         ioSession.removeAttribute(HttpResponseDecoder.CURRENT_RESPONSE);
+        if (timeoutDelay > 0) {
+            sentQueue.clear();
+            scheduler.purge();
+            scheduler.shutdownNow();
+            scheduler = null;
+        }
         callback.onClosed();
     }
+
+    public void messageSent(IoSession ioSession, Object object) throws Exception {
+        HttpRequestMessage msg = (HttpRequestMessage) object;
+        if (timeoutDelay > 0) {
+            TimeoutTask task = new TimeoutTask(ioSession);
+            scheduler.schedule(task, timeoutDelay, TimeUnit.MILLISECONDS);
+            sentQueue.add(msg);
+        }
+    }
+
+    /**
+     * Task to remove cancelled tasks from the scheduler
+     */
+    class SchedulePurger implements Runnable {
+
+        public void run() {
+            scheduler.purge();
+        }
+
+    }
+
+    class TimeoutTask implements Runnable {
+
+        private IoSession sess;
+
+        public TimeoutTask(IoSession sess) {
+            this.sess = sess;
+        }
+
+        public void run() {
+            callback.onTimeout();
+            //Close the session, its no good since the server is timing out
+            sess.close();
+        }
+
+    }
+
+
 }

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
Wed Sep  5 16:09:57 2007
@@ -22,6 +22,7 @@
 import java.net.ProtocolException;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.concurrent.ScheduledFuture;
 
 public class HttpRequestMessage extends HttpMessage{
 
@@ -37,12 +38,21 @@
     private String path;
     private Map<String, String> parameters = new HashMap<String,String>();
     private String userAgent = "AsyncHttpClient 1.0";
-
+    private boolean followRedirects = true;
+    private ScheduledFuture timeoutHandle = null;
 
     public HttpRequestMessage(String path) {
         this.path = path;
     }
 
+    protected ScheduledFuture getTimeoutHandle() {
+        return timeoutHandle;
+    }
+
+    protected void setTimeoutHandle(ScheduledFuture timeoutHandle) {
+        this.timeoutHandle = timeoutHandle;
+    }
+
     public String getRequestMethod() {
         return requestMethod;
     }
@@ -95,5 +105,13 @@
 
     public void setUserAgent(String userAgent) {
         this.userAgent = userAgent;
+    }
+
+    public boolean isFollowRedirects() {
+        return followRedirects;
+    }
+
+    public void setFollowRedirects(boolean followRedirects) {
+        this.followRedirects = followRedirects;
     }
 }

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java
Wed Sep  5 16:09:57 2007
@@ -35,10 +35,12 @@
     
     private int statusCode;
     private String statusMessage;
+    private String connection;
 
     private boolean chunked = false;
     private int expectedToRead = -1;
     private int state = STATE_START;
+    private String location = null;
 
     public int getStatusCode() {
         return statusCode;
@@ -80,4 +82,19 @@
         this.state = state;
     }
 
+    public String getLocation() {
+        return location;
+    }
+
+    public void setLocation(String location) {
+        this.location = location;
+    }
+
+    public String getConnection() {
+        return connection;
+    }
+
+    public void setConnection(String connection) {
+        this.connection = connection;
+    }
 }

Added: geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/timeout.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/timeout.jsp?rev=573094&view=auto
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/timeout.jsp (added)
+++ geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/timeout.jsp Wed Sep  5
16:09:57 2007
@@ -0,0 +1,5 @@
+<%
+    Thread.sleep(5000);
+%>
+Hello World!
+

Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java Wed Sep
 5 16:09:57 2007
@@ -26,6 +26,7 @@
 import org.apache.catalina.Host;
 import org.apache.catalina.Context;
 import org.apache.catalina.core.StandardHost;
+import org.apache.ahc.codec.HttpResponseMessage;
 
 import java.io.File;
 
@@ -38,6 +39,7 @@
     protected final File WEBAPPS = new File(CATALINAHOME, "webapps");
     protected final File ROOT = new File(WEBAPPS, "ROOT");
     protected Embedded server;
+    protected static final Object semaphore = new Object();
 
     protected void setUp() throws Exception {
         System.out.println("BASEDIR = " + BASEDIR.getAbsolutePath());
@@ -93,5 +95,85 @@
         }
 
         return dir;
+    }
+
+        class TestCallback implements AHCCallback{
+
+        private boolean timeout = false;
+        private boolean closed = false;
+        private boolean exception = false;
+        private Throwable throwable = null;
+        private HttpResponseMessage message = null;
+        public TestCallback() {
+            clear();
+        }
+
+        public void onResponse(HttpResponseMessage message) {
+            this.message = message;
+            synchronized(semaphore){
+                semaphore.notify();
+            }
+        }
+
+        public void onException(Throwable cause) {
+            throwable = cause;
+            exception = true;
+            synchronized(semaphore){
+                semaphore.notify();
+            }
+        }
+
+        public void onClosed() {
+            closed = true;
+            synchronized(semaphore){
+                semaphore.notify();
+            }
+        }
+
+        public void onTimeout() {
+            timeout = true;
+            synchronized(semaphore){
+                semaphore.notify();
+            }
+        }
+
+        public Throwable getThrowable() {
+            return throwable;
+        }
+
+        public void clear(){
+            closed = false;
+            timeout = false;
+            exception = false;
+            message = null;
+        }
+
+        public boolean isClosed() {
+            return closed;
+        }
+
+        public void setClosed(boolean closed) {
+            this.closed = closed;
+        }
+
+        public boolean isTimeout() {
+            return timeout;
+        }
+
+        public boolean isException() {
+            return exception;
+        }
+
+        public void setException(boolean exception) {
+            this.exception = exception;
+        }
+
+        public HttpResponseMessage getMessage() {
+            return message;
+        }
+
+        public void setMessage(HttpResponseMessage message) {
+            this.message = message;
+        }
     }
 }

Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java?rev=573094&r1=573093&r2=573094&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
Wed Sep  5 16:09:57 2007
@@ -29,7 +29,6 @@
 
 public class AsyncHttpClientTest extends AbstractTest {
 
-    protected static final Object semaphore = new Object();
 
     public void testHtmlConnection() throws Exception {
         TestCallback callback = new TestCallback();
@@ -132,70 +131,4 @@
 
     }
 
-    class TestCallback implements AHCCallback{
-
-        private boolean closed = false;
-        private boolean exception = false;
-        private Throwable throwable = null;
-        private HttpResponseMessage message = null;
-        public TestCallback() {
-            clear();
-        }
-
-        public void onResponse(HttpResponseMessage message) {
-            this.message = message;
-            synchronized(semaphore){
-                semaphore.notify();
-            }
-        }
-
-        public void onException(Throwable cause) {
-            throwable = cause;
-            exception = true;
-            synchronized(semaphore){
-                semaphore.notify();
-            }
-        }
-
-        public void onClosed() {
-            closed = true;
-            synchronized(semaphore){
-                semaphore.notify();
-            }
-        }
-
-        public Throwable getThrowable() {
-            return throwable;
-        }
-
-        public void clear(){
-            closed = false;
-            exception = false;
-            message = null;
-        }
-        
-        public boolean isClosed() {
-            return closed;
-        }
-
-        public void setClosed(boolean closed) {
-            this.closed = closed;
-        }
-
-        public boolean isException() {
-            return exception;
-        }
-
-        public void setException(boolean exception) {
-            this.exception = exception;
-        }
-
-        public HttpResponseMessage getMessage() {
-            return message;
-        }
-
-        public void setMessage(HttpResponseMessage message) {
-            this.message = message;
-        }
-    }
 }

Added: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java?rev=573094&view=auto
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java (added)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java Wed Sep
 5 16:09:57 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.ahc;
+
+import org.apache.ahc.codec.HttpRequestMessage;
+
+import java.net.URL;
+
+public class TimeoutTest extends AbstractTest {
+
+    public void testTimeout() throws Exception{
+
+        TestCallback callback = new TestCallback();
+
+        //Create a client with a one second timeout
+        AsyncHttpClient ahc = new AsyncHttpClient(new URL("http://localhost:8282"), callback,
30000, 1000);
+        ahc.connect();
+
+        HttpRequestMessage request = new HttpRequestMessage("/timeout.jsp");
+
+        ahc.sendRequest(request);
+
+        //We are done...Thread would normally end...
+        //So this little wait simulates the thread going back in the pool
+        synchronized(semaphore){
+            //5 second timeout due to no response
+            semaphore.wait(5000);
+        }
+
+        assertTrue(callback.isTimeout());
+
+    }
+}



Mime
View raw message