Clear up state handling a bit
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 30 Mar 2010 16:03:32 +0000 (16:03 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 30 Mar 2010 16:03:32 +0000 (16:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@929181 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/CoyoteAdapter.java
java/org/apache/catalina/core/AsyncContextImpl.java
java/org/apache/coyote/http11/Http11Processor.java

index b71fe1d..7ba0610 100644 (file)
@@ -280,7 +280,7 @@ public class CoyoteAdapter implements Adapter {
                 AsyncContextImpl asyncConImpl = (AsyncContextImpl)request.getAsyncContext();
                 //TODO SERVLET3 - async
                 //configure settings for timed out
-                asyncConImpl.setErrorState();
+                asyncConImpl.setErrorState(new IOException("Socket error."));
             }
             while (success) {
                 AsyncContextImpl impl = (AsyncContextImpl)request.getAsyncContext();
@@ -302,12 +302,15 @@ public class CoyoteAdapter implements Adapter {
                         //TODO SERVLET3 - async
                         async = false;
                         break;
+                } else if (impl.getState()==AsyncContextImpl.AsyncState.ERROR_DISPATCHING) {
+                    async = false;
+                    success = false;
+                    connector.getContainer().getPipeline().getFirst().invoke(request, response);
                 } else {
                     try {
                         connector.getContainer().getPipeline().getFirst().invoke(request, response);
-                    }catch (RuntimeException x) {
-                        success = false;
-                    } finally {
+                    } catch (RuntimeException x) {
+                        impl.setErrorState(x);
                     }
                 }
             }
@@ -394,7 +397,7 @@ public class CoyoteAdapter implements Adapter {
         }
 
         boolean comet = false;
-        boolean async = request.isAsyncStarted();
+        boolean async = false;
         
         try {
 
@@ -431,12 +434,12 @@ public class CoyoteAdapter implements Adapter {
             if (asyncConImpl!=null && asyncConImpl.getState()==AsyncContextImpl.AsyncState.STARTED) {
                 res.action(ActionCode.ACTION_ASYNC_START, request.getAsyncContext());
                 async = true;
-            } else if (asyncConImpl!=null && 
-                          (asyncConImpl.getState()==AsyncContextImpl.AsyncState.DISPATCHING ||
-                           asyncConImpl.getState()==AsyncContextImpl.AsyncState.COMPLETING  ||
-                           asyncConImpl.getState()==AsyncContextImpl.AsyncState.TIMING_OUT  ||
-                           asyncConImpl.getState()==AsyncContextImpl.AsyncState.ERROR_DISPATCHING)) {
+            } else if (request.isAsyncDispatching()) {
                 asyncDispatch(req, res, SocketStatus.OPEN);
+                if (request.isAsyncStarted()) {
+                    async = true;
+                    res.action(ActionCode.ACTION_ASYNC_START, request.getAsyncContext());
+                }
             } else if (!comet) {
                 response.finishResponse();
                 req.action(ActionCode.ACTION_POST_REQUEST , null);
index c699bde..b3c800f 100644 (file)
@@ -389,7 +389,8 @@ public class AsyncContextImpl implements AsyncContext {
         state.set(AsyncState.TIMING_OUT);
     }
     
-    public void setErrorState() {
+    public void setErrorState(Throwable t) {
+        if (t!=null) request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
         state.set(AsyncState.ERROR_DISPATCHING);
     }
     
index 54bd9a9..a881746 100644 (file)
@@ -318,21 +318,19 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
         }
 
         rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
-        if (async) {
-            if (error) {
-                recycle();
-                return SocketState.CLOSED;
-            } else {
-                return SocketState.LONG;
-            }
+        if (error) {
+            recycle();
+            return SocketState.CLOSED;
+        } else if (async) {
+            return SocketState.LONG;
         } else {
-            if ( error || (!keepAlive)) {
+            if (!keepAlive) {
                 recycle();
                 return SocketState.CLOSED;
             } else {
                 return SocketState.OPEN;
             }
-        }
+        } 
     }
     
     
@@ -353,15 +351,13 @@ public class Http11Processor extends AbstractHttp11Processor implements ActionHo
 
         rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
 
-        if (async) {
-            if (error) {
-                recycle();
-                return SocketState.CLOSED;
-            } else {
-                return SocketState.LONG;
-            }
+        if (error) {
+            recycle();
+            return SocketState.CLOSED;
+        } else if (async) {
+            return SocketState.LONG;
         } else {
-            if ( error || (!keepAlive)) {
+            if (!keepAlive) {
                 recycle();
                 return SocketState.CLOSED;
             } else {