incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r585113 - in /incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet: MicroSlingFilterHelper.java MicroSlingServlet.java
Date Tue, 16 Oct 2007 11:06:35 GMT
Author: fmeschbe
Date: Tue Oct 16 04:06:24 2007
New Revision: 585113

URL: http://svn.apache.org/viewvc?rev=585113&view=rev
Log:
Ensure the filters are destroyed when the MicroSlingServlet is destroyed

Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java?rev=585113&r1=585112&r2=585113&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
Tue Oct 16 04:06:24 2007
@@ -35,7 +35,7 @@
 /** Manages the microsling chain of servlet Filters:
  *  stores the list, calls them when processing a request
  *  and calls microSlingServlet.doService after that.
- *  
+ *
  *  This is utility code, not very interesting to study.
  */
 class MicroSlingFilterHelper {
@@ -50,6 +50,23 @@
         this.microSling = microSling;
     }
 
+    void destroy() {
+        Filter[] filters = getFilters();
+
+        // clean up
+        requestFilterList.clear();
+        requestFilters = null;
+
+        // destroy the filters
+        for (int i=0; i < filters.length; i++) {
+            try {
+                filters[i].destroy();
+            } catch (Throwable t) {
+                // TODO: some logging would probably be usefull
+            }
+        }
+    }
+
     /*
      * (non-Javadoc)
      *
@@ -105,7 +122,7 @@
 
     /** A FilterChain that applies all Filters in an array and calls
      *  MicroSlingServlet.doFilter when done
-     */ 
+     */
     private static class MicroSlingFilterChain implements FilterChain {
 
         private final MicroSlingServlet microSlingServlet;
@@ -129,7 +146,7 @@
             if (currentFilter < requestFilters.length) {
                 // call the next filter
                 requestFilters[currentFilter].doFilter(request, response, this);
-                
+
             } else {
                 // done with filters, call microsling servlet
                 HttpServletRequest hReq = null;

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?rev=585113&r1=585112&r2=585113&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java
Tue Oct 16 04:06:24 2007
@@ -44,7 +44,7 @@
 /**
  * The main microsling servlet: apply Filters to the request using our
  * MicroSlingFilterHelper, select and delegate to a SlingServlet
- * to process the request.  
+ * to process the request.
  */
 public class MicroSlingServlet extends GenericServlet {
 
@@ -77,14 +77,25 @@
     }
 
     /** Execute our Filters via MicroSlingFilterHelper, which
-     *  calls our doService method after executing the filters 
+     *  calls our doService method after executing the filters
      */
     public void service(ServletRequest req, ServletResponse resp)
             throws ServletException, IOException {
-        
+
         // our filters might need the SlingRequestContext to store info in it
         new SlingRequestContext(getServletContext(),req);
         filterChain.service(req, resp);
+    }
+
+    @Override
+    public void destroy() {
+        super.destroy();
+
+        // just for completeness, we have to take down our filters
+        if (filterChain != null) {
+            filterChain.destroy();
+            filterChain = null;
+        }
     }
 
     /**



Mime
View raw message