the dispatcher type should be ASYNC when we are doing a dispatch
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 17 Jul 2009 22:37:54 +0000 (22:37 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 17 Jul 2009 22:37:54 +0000 (22:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@795256 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/AsyncContextImpl.java
java/org/apache/catalina/connector/CoyoteAdapter.java
java/org/apache/catalina/core/ApplicationDispatcher.java
java/org/apache/catalina/core/StandardWrapperValve.java
webapps/examples/jsp/async/async1.jsp

index 4824c5c..8753335 100644 (file)
@@ -64,7 +64,9 @@ public class AsyncContextImpl implements AsyncContext {
 
     @Override
     public void dispatch() {
-        // TODO SERVLET3 - async
+        HttpServletRequest sr = (HttpServletRequest)getServletRequest();
+        String path = sr.getRequestURI();
+        dispatch(path);
     }
 
     @Override
@@ -84,6 +86,7 @@ public class AsyncContextImpl implements AsyncContext {
                 try {
                     //piggy back on the request dispatcher to ensure that filters etc get called.
                     //TODO SERVLET3 - async should this be include/forward or a new dispatch type
+                    //javadoc suggests include with the type of DispatcherType.ASYNC
                     requestDispatcher.include(servletRequest, servletResponse);
                 }catch (Exception x) {
                     //log.error("Async.dispatch",x);
index 11f3cef..559dd8f 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.catalina.connector;
 import java.io.IOException;
 import java.util.EnumSet;
 
+import javax.servlet.DispatcherType;
 import javax.servlet.SessionTrackingMode;
 
 import org.apache.catalina.CometEvent;
@@ -262,11 +263,15 @@ public class CoyoteAdapter
         boolean success = true;
         
         try {
+            DispatcherType prevDispatcherType = request.getDispatcherType();
+            request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.ASYNC);
             // Calling the container
             try {
                 connector.getContainer().getPipeline().getFirst().invoke(request, response);
             }catch (RuntimeException x) {
                 success = false;
+            } finally {
+                request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, prevDispatcherType);
             }
 
             if (request.isComet()) {
index 4fd8332..fdc29e4 100644 (file)
@@ -96,7 +96,9 @@ final class ApplicationDispatcher
         }
 
         public Void run() throws ServletException, IOException {
-            doInclude(request,response);
+            DispatcherType type = DispatcherType.INCLUDE;
+            if (request.getDispatcherType()==DispatcherType.ASYNC) type = DispatcherType.ASYNC; 
+            doInclude(request,response,type);
             return null;
         }
     }
@@ -487,11 +489,13 @@ final class ApplicationDispatcher
                 throw (IOException) e;
             }
         } else {
-            doInclude(request,response);
+            DispatcherType type = DispatcherType.INCLUDE;
+            if (request.getDispatcherType()==DispatcherType.ASYNC) type = DispatcherType.ASYNC; 
+            doInclude(request,response,type);
         }
     }
 
-    private void doInclude(ServletRequest request, ServletResponse response)
+    private void doInclude(ServletRequest request, ServletResponse response, DispatcherType type)
         throws ServletException, IOException
     {
         // Set up to handle the specified request and response
@@ -514,7 +518,7 @@ final class ApplicationDispatcher
             if (servletPath != null)
                 wrequest.setServletPath(servletPath);
             wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                    DispatcherType.INCLUDE);
+                    type);
             wrequest.setAttribute(
                     ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
                     getCombinedPath());
@@ -546,7 +550,7 @@ final class ApplicationDispatcher
             }
             
             wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-                    DispatcherType.INCLUDE);
+                    type);
             wrequest.setAttribute(
                     ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
                     getCombinedPath());
index bd08ae3..049aee1 100644 (file)
@@ -183,9 +183,11 @@ final class StandardWrapperValve
             servlet = null;
         }
         MessageBytes requestPathMB = request.getRequestPathMB();
+        DispatcherType dispatcherType = DispatcherType.REQUEST;
+        if (request.getDispatcherType()==DispatcherType.ASYNC) dispatcherType = DispatcherType.ASYNC; 
         request.setAttribute
             (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
-             DispatcherType.REQUEST);
+             dispatcherType);
         request.setAttribute
             (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
              requestPathMB);
index 2555765..474e333 100644 (file)
@@ -1,5 +1,6 @@
 <%@page session="false"%>
 Output from async1.jsp
+Type is <%=request.getDispatcherType()%>
 <%
 System.out.println("Inside Async 1");
   if (request.isAsyncStarted()) {