incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r685500 - /incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Date Wed, 13 Aug 2008 10:19:48 GMT
Author: cziegeler
Date: Wed Aug 13 03:19:45 2008
New Revision: 685500

URL: http://svn.apache.org/viewvc?rev=685500&view=rev
Log:
SLING-610 : Decrement recursion counter after include.

Modified:
    incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java

Modified: incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=685500&r1=685499&r2=685500&view=diff
==============================================================================
--- incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Wed Aug 13 03:19:45 2008
@@ -151,8 +151,8 @@
 
     private SlingAuthenticator slingAuthenticator;
 
-    public static final String INCLUDE_COUNTER = "Sling.ScriptHelper.include.counter";
-    public static final int MAX_INCLUDE_RECURSION_LEVEL = 50;
+    private static final String INCLUDE_COUNTER = "Sling.ScriptHelper.include.counter";
+    private static final int MAX_INCLUDE_RECURSION_LEVEL = 50;
 
     public static class InfiniteIncludeLoopException extends SlingException {
         InfiniteIncludeLoopException(String path) {
@@ -372,22 +372,26 @@
 
         checkRecursionLevel(request, resolvedURL.getResourcePath());
 
-        // we need a SlingHttpServletRequest/SlingHttpServletResponse tupel to continue
-        SlingHttpServletRequest cRequest = RequestData.toSlingHttpServletRequest(request);
-        SlingHttpServletResponse cResponse = RequestData.toSlingHttpServletResponse(response);
-
-        // get the request data (and btw check the correct type)
-        RequestData requestData = RequestData.getRequestData(cRequest);
-        ContentData contentData = requestData.pushContent(resource, resolvedURL);
-
         try {
-            // resolve the servlet
-            Servlet servlet = getServletResolver().resolveServlet(cRequest);
-            contentData.setServlet(servlet);
+            // we need a SlingHttpServletRequest/SlingHttpServletResponse tupel to continue
+            SlingHttpServletRequest cRequest = RequestData.toSlingHttpServletRequest(request);
+            SlingHttpServletResponse cResponse = RequestData.toSlingHttpServletResponse(response);
+
+            // get the request data (and btw check the correct type)
+            RequestData requestData = RequestData.getRequestData(cRequest);
+            ContentData contentData = requestData.pushContent(resource, resolvedURL);
 
-            processRequest(cRequest, cResponse);
+            try {
+                // resolve the servlet
+                Servlet servlet = getServletResolver().resolveServlet(cRequest);
+                contentData.setServlet(servlet);
+
+                processRequest(cRequest, cResponse);
+            } finally {
+                requestData.popContent();
+            }
         } finally {
-            requestData.popContent();
+            decreaseRecursionLevel(request);
         }
     }
 
@@ -405,6 +409,19 @@
         request.setAttribute(INCLUDE_COUNTER, recursionLevel);
     }
 
+    /** Decrease the recursion counter  */
+    protected void decreaseRecursionLevel(ServletRequest request) {
+        // this should never be null, but we better do a sanity check
+        final Integer recursionLevel = (Integer)request.getAttribute(INCLUDE_COUNTER);
+        if ( recursionLevel != null ) {
+            if ( recursionLevel == 1 ) {
+                request.removeAttribute(INCLUDE_COUNTER);
+            } else {
+                request.setAttribute(INCLUDE_COUNTER, new Integer(recursionLevel.intValue()
-1));
+            }
+        }
+    }
+
     public void processRequest(SlingHttpServletRequest request,
             SlingHttpServletResponse response) throws IOException,
             ServletException {
@@ -797,7 +814,7 @@
                         return ParameterSupport.getInstance(getRequest());
                     }
                 };
-                
+
                 return authenticator.authenticate(request, response);
 
             } catch (MissingRepositoryException mre) {



Mime
View raw message