felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1661820 - in /felix/trunk/http: base/src/main/java/org/apache/felix/http/base/internal/dispatch/ base/src/main/java/org/apache/felix/http/base/internal/runtime/ jetty/src/main/java/org/apache/felix/http/jetty/internal/
Date Mon, 23 Feb 2015 23:34:34 GMT
Author: cziegeler
Date: Mon Feb 23 23:34:33 2015
New Revision: 1661820

URL: http://svn.apache.org/r1661820
Log:
FELIX-4798 : Support async servlets (filters)

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
    felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=1661820&r1=1661819&r2=1661820&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
Mon Feb 23 23:34:33 2015
@@ -34,6 +34,7 @@ import java.io.IOException;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.servlet.AsyncContext;
 import javax.servlet.DispatcherType;
 import javax.servlet.FilterChain;
 import javax.servlet.RequestDispatcher;
@@ -91,7 +92,8 @@ public final class Dispatcher implements
 
             try
             {
-                ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest)
request, this.handler.getContext(), this.requestInfo, DispatcherType.FORWARD, this.handler.getContextServiceId());
+                ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest)
request, this.handler.getContext(), this.requestInfo, DispatcherType.FORWARD, this.handler.getContextServiceId(),
+                        handler.getServletInfo().isAsyncSupported());
                 Dispatcher.this.forward(this.handler, req, (HttpServletResponse) response);
             }
             finally
@@ -109,7 +111,8 @@ public final class Dispatcher implements
         @Override
         public void include(ServletRequest request, ServletResponse response) throws ServletException,
IOException
         {
-            ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
this.handler.getContext(), this.requestInfo, DispatcherType.INCLUDE, this.handler.getContextServiceId());
+            ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
this.handler.getContext(), this.requestInfo, DispatcherType.INCLUDE,
+                    this.handler.getContextServiceId(), handler.getServletInfo().isAsyncSupported());
             Dispatcher.this.include(this.handler, req, (HttpServletResponse) response);
         }
     }
@@ -205,7 +208,8 @@ public final class Dispatcher implements
 
                                 final FilterHandler[] filterHandlers = handlerRegistry.getFilterHandlers(errorHandler,
DispatcherType.ERROR, request.getRequestURI());
 
-                                invokeChain(filterHandlers, errorHandler, new ServletRequestWrapper(request,
errorHandler.getContext(), requestInfo, this.serviceId), this);
+                                // TODO - is async = false correct?
+                                invokeChain(filterHandlers, errorHandler, new ServletRequestWrapper(request,
errorHandler.getContext(), requestInfo, this.serviceId, false), this);
 
                                 invokeSuper = false;
                             }
@@ -239,17 +243,20 @@ public final class Dispatcher implements
         private final RequestInfo requestInfo;
         private final ExtServletContext servletContext;
         private final Long contextId;
+        private final boolean asyncSupported;
 
-        public ServletRequestWrapper(HttpServletRequest req, ExtServletContext servletContext,
RequestInfo requestInfo, final Long contextId)
+        public ServletRequestWrapper(HttpServletRequest req, ExtServletContext servletContext,
RequestInfo requestInfo, final Long contextId,
+                final boolean asyncSupported)
         {
-            this(req, servletContext, requestInfo, null /* type */, contextId);
+            this(req, servletContext, requestInfo, null /* type */, contextId, asyncSupported);
         }
 
         public ServletRequestWrapper(HttpServletRequest req, ExtServletContext servletContext,
RequestInfo requestInfo,
-                DispatcherType type, final Long contextId)
+                DispatcherType type, final Long contextId, final boolean asyncSupported)
         {
             super(req);
 
+            this.asyncSupported = asyncSupported;
             this.servletContext = servletContext;
             this.requestInfo = requestInfo;
             this.type = type;
@@ -497,6 +504,33 @@ public final class Dispatcher implements
         {
             return (DispatcherType.INCLUDE == this.type) && (this.requestInfo !=
null);
         }
+
+        @Override
+        public AsyncContext startAsync() throws IllegalStateException
+        {
+            if ( !this.asyncSupported )
+            {
+                throw new IllegalStateException();
+            }
+            return super.startAsync();
+        }
+
+        @Override
+        public AsyncContext startAsync(final ServletRequest servletRequest,
+                final ServletResponse servletResponse) throws IllegalStateException
+        {
+            if ( !this.asyncSupported )
+            {
+                throw new IllegalStateException();
+            }
+            return super.startAsync(servletRequest, servletResponse);
+        }
+
+        @Override
+        public boolean isAsyncSupported()
+        {
+            return this.asyncSupported;
+        }
     }
 
     private static class RequestInfo
@@ -586,7 +620,8 @@ public final class Dispatcher implements
         ExtServletContext servletContext = (servletHandler != null) ? servletHandler.getContext()
: null;
         final RequestInfo requestInfo = new RequestInfo(servletPath, pathInfo, queryString);
 
-        final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext,
requestInfo, servletHandler.getContextServiceId());
+        final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext,
requestInfo, servletHandler.getContextServiceId(),
+                servletHandler.getServletInfo().isAsyncSupported());
         final FilterHandler[] filterHandlers = this.handlerRegistry.getFilterHandlers(servletHandler,
req.getDispatcherType(), requestURI);
 
         try

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java?rev=1661820&r1=1661819&r2=1661820&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
Mon Feb 23 23:34:33 2015
@@ -117,7 +117,7 @@ public final class ServletInfo extends W
             this.patterns = new String[] {pattern, pattern + "/*"};
         }
         this.initParams = initParams;
-        this.asyncSupported = false;
+        this.asyncSupported = true;
         this.errorPage = null;
     }
 

Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java?rev=1661820&r1=1661819&r2=1661820&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
(original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
Mon Feb 23 23:34:33 2015
@@ -247,7 +247,9 @@ public final class JettyService extends
             configureSessionManager(context);
             context.addEventListener(eventDispatcher);
             context.getSessionHandler().addEventListener(eventDispatcher);
-            context.addServlet(new ServletHolder(this.dispatcher), "/*");
+            final ServletHolder holder = new ServletHolder(this.dispatcher);
+            holder.setAsyncSupported(true);
+            context.addServlet(holder, "/*");
             context.setMaxFormContentSize(this.config.getMaxFormSize());
 
             if (this.config.isRegisterMBeans())



Mime
View raw message