One more use case
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 6 Aug 2009 19:34:34 +0000 (19:34 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 6 Aug 2009 19:34:34 +0000 (19:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@801789 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/ApplicationFilterChain.java
java/org/apache/catalina/core/StandardWrapperValve.java
java/org/apache/coyote/http11/Http11NioProcessor.java
webapps/examples/WEB-INF/classes/async/Async3.java [new file with mode: 0644]
webapps/examples/WEB-INF/web.xml
webapps/examples/jsp/async/async3.jsp [new file with mode: 0644]
webapps/examples/jsp/async/index.jsp

index c2790c4..2b577a9 100644 (file)
@@ -160,6 +160,8 @@ final class ApplicationFilterChain implements FilterChain, CometFilterChain {
      */                                                 
     private static Class<?>[] classTypeUsedInEvent = 
         new Class[] { CometEvent.class };
+    
+    
 
     // ---------------------------------------------------- FilterChain Methods
 
@@ -570,6 +572,16 @@ final class ApplicationFilterChain implements FilterChain, CometFilterChain {
         this.support = support;
 
     }
+    
+    public boolean isAsyncSupported() {
+        boolean supported = true;
+        for (ApplicationFilterConfig config : filters) {
+            if (config!=null && config.getFilterDef()!=null) {
+                supported = supported & config.getFilterDef().isAsyncSupported();
+            }
+        }
+        return supported;
+    }
 
 
 }
index 049aee1..2f0b266 100644 (file)
@@ -196,8 +196,11 @@ final class StandardWrapperValve
             ApplicationFilterFactory.getInstance();
         ApplicationFilterChain filterChain =
             factory.createFilterChain(request, wrapper, servlet);
+        
         // Reset comet flag value after creating the filter chain
         request.setComet(false);
+        //check filters to see if we support async or not.
+        request.setAsyncSupported(filterChain.isAsyncSupported());
 
         // Call the filter chain for this request
         // NOTE: This also calls the servlet's service() method
index 5926147..aadcd75 100644 (file)
@@ -1326,8 +1326,9 @@ public class Http11NioProcessor implements ActionHook {
             AtomicBoolean dispatch = (AtomicBoolean)param;
             if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) {//async handling
                 endpoint.processSocket(this.socket, SocketStatus.OPEN, true);
-            } else { 
                 dispatch.set(true);
+            } else { 
+                
             }
         }
     }
diff --git a/webapps/examples/WEB-INF/classes/async/Async3.java b/webapps/examples/WEB-INF/classes/async/Async3.java
new file mode 100644 (file)
index 0000000..1d4a7e1
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+* 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 async;
+
+import java.io.IOException;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class Async3 extends HttpServlet {
+    protected static Log log = LogFactory.getLog(Async3.class);
+    public Async3() {
+    }
+
+    @Override
+    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        final AsyncContext actx = req.startAsync();
+        actx.setAsyncTimeout(30*1000);
+        actx.dispatch("/jsp/async/async3.jsp");
+        actx.complete();
+    }
+    
+
+}
index dd51c02..ea64cb2 100644 (file)
       <servlet-name>async2</servlet-name>
       <url-pattern>/async/async2</url-pattern>
     </servlet-mapping>
+    <servlet>
+      <servlet-name>async3</servlet-name>
+      <servlet-class>async.Async3</servlet-class>
+    </servlet>
+    <servlet-mapping>
+      <servlet-name>async3</servlet-name>
+      <url-pattern>/async/async3</url-pattern>
+    </servlet-mapping>
 </web-app>
diff --git a/webapps/examples/jsp/async/async3.jsp b/webapps/examples/jsp/async/async3.jsp
new file mode 100644 (file)
index 0000000..089a034
--- /dev/null
@@ -0,0 +1,4 @@
+<%@page session="false"%>
+Output from async3.jsp
+Type is <%=request.getDispatcherType()%>
+Completed async 3 request at <%=new java.sql.Date(System.currentTimeMillis())%>
\ No newline at end of file
index 0e32767..b75c851 100644 (file)
@@ -18,6 +18,11 @@ Use cases:
  - background thread calls writes and calls complete()
    <a href="<%=response.encodeURL("/examples/async/async2")%>"> Async 2 </a>
 
+4. Simple dispatch
+ - servlet does a startAsync()
+ - servlet calls dispatch(/path/to/jsp)
+ - servlet calls complete()
+   <a href="<%=response.encodeURL("/examples/async/async3")%>"> Async 3 </a>
 
 3. Timeout s1
  - servlet does a startAsync()