tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r801824 - in /tomcat/trunk/java/org/apache/catalina: Globals.java connector/AsyncContextImpl.java connector/CoyoteAdapter.java connector/Request.java core/ApplicationDispatcher.java core/ApplicationHttpRequest.java
Date Thu, 06 Aug 2009 22:19:08 GMT
Author: fhanik
Date: Thu Aug  6 22:19:08 2009
New Revision: 801824

URL: http://svn.apache.org/viewvc?rev=801824&view=rev
Log:
Add in handling of async supported for filters during regular invokation and a dispatch 

Modified:
    tomcat/trunk/java/org/apache/catalina/Globals.java
    tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationHttpRequest.java

Modified: tomcat/trunk/java/org/apache/catalina/Globals.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Globals.java?rev=801824&r1=801823&r2=801824&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Globals.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Globals.java Thu Aug  6 22:19:08 2009
@@ -329,6 +329,11 @@
      */
     public static final boolean IS_SECURITY_ENABLED =
         (System.getSecurityManager() != null);
-
+    
+    /**
+     * 
+     */
+    public static final String ASYNC_SUPPORTED_ATTR = 
+        "org.apache.catalina.ASYNC_SUPPORTED";
 
 }

Modified: tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java?rev=801824&r1=801823&r2=801824&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/AsyncContextImpl.java Thu Aug  6 22:19:08
2009
@@ -24,6 +24,7 @@
 
 import javax.servlet.AsyncContext;
 import javax.servlet.AsyncListener;
+import javax.servlet.DispatcherType;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -33,6 +34,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.Context;
+import org.apache.catalina.Globals;
 import org.apache.coyote.ActionCode;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -110,14 +112,18 @@
             final HttpServletResponse servletResponse = (HttpServletResponse)getResponse();
             Runnable run = new Runnable() {
                 public void run() {
+                    DispatcherType type = (DispatcherType)request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
                     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
+                        request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.ASYNC);
                         requestDispatcher.include(servletRequest, servletResponse);
                     }catch (Exception x) {
                         //log.error("Async.dispatch",x);
                         throw new RuntimeException(x);
+                    }finally {
+                        request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, type);
                     }
                 }
             };

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=801824&r1=801823&r2=801824&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu Aug  6 22:19:08
2009
@@ -263,8 +263,6 @@
         boolean success = true;
         
         try {
-            DispatcherType prevDispatcherType = request.getDispatcherType();
-            request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, DispatcherType.ASYNC);
             // Calling the container
             try {
                 if (status==SocketStatus.TIMEOUT) {
@@ -283,7 +281,6 @@
             }catch (RuntimeException x) {
                 success = false;
             } finally {
-                request.setAttribute(Globals.DISPATCHER_TYPE_ATTR, prevDispatcherType);
             }
 
             if (request.isComet()) {

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=801824&r1=801823&r2=801824&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Thu Aug  6 22:19:08 2009
@@ -386,11 +386,6 @@
     protected String localName = null;
     
     /**
-     * asyncSupported
-     */
-    protected boolean asyncSupported = true;
-    
-    /**
      * AsyncContext 
      */
     protected AsyncContextImpl asyncContext = null;
@@ -400,6 +395,8 @@
      */
     protected long asyncTimeout = 0;
     
+    protected Boolean asyncSupported = null;
+    
     
 
     // --------------------------------------------------------- Public Methods
@@ -407,7 +404,7 @@
     
 
     public void setAsyncSupported(boolean asyncSupported) {
-        this.asyncSupported = asyncSupported;
+        asyncSupported = asyncSupported?Boolean.TRUE:Boolean.FALSE;
     }
 
     /**
@@ -483,7 +480,7 @@
             }
         }
         
-        asyncSupported = true;
+        asyncSupported = null;
         if (asyncContext!=null) asyncContext.recycle();
 
     }
@@ -850,6 +847,10 @@
                 ? getRequestPathMB().toString()
                 : requestDispatcherPath.toString();
         }
+        
+        if (name.equals(Globals.ASYNC_SUPPORTED_ATTR)) {
+            return isAsyncSupported();
+        }
 
         Object attr=attributes.get(name);
 
@@ -1370,6 +1371,10 @@
             requestDispatcherPath = value;
             return;
         }
+        
+        if (name.equals(Globals.ASYNC_SUPPORTED_ATTR)) {
+            this.asyncSupported = (Boolean)value;
+        }
 
         Object oldValue = null;
         boolean replaced = false;
@@ -1487,7 +1492,11 @@
 
     public boolean isAsyncSupported() {
         // TODO SERVLET3 - async
-        return this.asyncSupported;
+        if (this.asyncSupported==null) { 
+            return true;
+        } else {
+            return asyncSupported.booleanValue();
+        }
     }
 
     public AsyncContext getAsyncContext() {

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java?rev=801824&r1=801823&r2=801824&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationDispatcher.java Thu Aug  6 22:19:08
2009
@@ -47,6 +47,8 @@
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.connector.ResponseFacade;
 import org.apache.catalina.util.InstanceSupport;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -66,6 +68,7 @@
 final class ApplicationDispatcher
     implements RequestDispatcher {
 
+    protected static Log log = LogFactory.getLog(ApplicationDispatcher.class);
 
     protected class PrivilegedForward
             implements PrivilegedExceptionAction<Void> {
@@ -637,6 +640,16 @@
         ApplicationFilterFactory factory = ApplicationFilterFactory.getInstance();
         ApplicationFilterChain filterChain = factory.createFilterChain(request,
                                                                 wrapper,servlet);
+        
+        Object asyncSupported = request.getAttribute(Globals.ASYNC_SUPPORTED_ATTR);
+        //we have a new filter chain, setup isAsyncSupported here
+        boolean filterAsyncSupported = filterChain.isAsyncSupported();
+        if (!filterAsyncSupported && request.isAsyncSupported()) {
+            //the request says we support it, but the filters don't
+            //TODO SERVLET3 - async
+            request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, Boolean.FALSE);
+        }
+        
         // Call the service() method for the allocated servlet instance
         try {
             String jspFile = wrapper.getJspFile();
@@ -691,6 +704,8 @@
             wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
                              wrapper.getName()), e);
             runtimeException = e;
+        } finally {
+            request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, asyncSupported);
         }
 
         // Release the filter chain (if any) for this request
@@ -777,8 +792,7 @@
         }
 
     }
-
-
+    
     /**
      * Unwrap the response if we have wrapped it.
      */

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationHttpRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationHttpRequest.java?rev=801824&r1=801823&r2=801824&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationHttpRequest.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationHttpRequest.java Thu Aug  6 22:19:08
2009
@@ -196,7 +196,7 @@
      * Special attributes.
      */
     protected Object[] specialAttributes = new Object[specials.length];
-
+    
 
     // ------------------------------------------------- ServletRequest Methods
 
@@ -741,10 +741,8 @@
         this.queryParamString = queryString;
     }
 
-
     // ------------------------------------------------------ Protected Methods
 
-
     /**
      * Is this attribute name one of the special ones that is added only for
      * included servlets?



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message