incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1183418 - in /sling/trunk/bundles/engine/src/main: java/org/apache/sling/engine/impl/SlingMainServlet.java java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java resources/OSGI-INF/metatype/metatype.properties
Date Fri, 14 Oct 2011 16:47:35 GMT
Author: justin
Date: Fri Oct 14 16:47:34 2011
New Revision: 1183418

URL: http://svn.apache.org/viewvc?rev=1183418&view=rev
Log:
SLING-2247 - adding support for limiting the recorded requests in the Recent Requests web
console plugin

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
    sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=1183418&r1=1183417&r2=1183418&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Fri Oct 14 16:47:34 2011
@@ -20,10 +20,13 @@ package org.apache.sling.engine.impl;
 
 import java.io.IOException;
 import java.net.SocketException;
+import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import javax.servlet.GenericServlet;
 import javax.servlet.ServletException;
@@ -37,6 +40,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
@@ -103,6 +107,9 @@ public class SlingMainServlet extends Ge
     @Property(intValue = RequestHistoryConsolePlugin.STORED_REQUESTS_COUNT)
     private static final String PROP_MAX_RECORD_REQUESTS = "sling.max.record.requests";
 
+    @Property(unbounded=PropertyUnbounded.ARRAY)
+    private static final String PROP_TRACK_PATTERNS_REQUESTS = "sling.store.pattern.requests";
+
     @Property
     private static final String PROP_DEFAULT_PARAMETER_ENCODING = "sling.default.parameter.encoding";
 
@@ -406,7 +413,12 @@ public class SlingMainServlet extends Ge
             int maxRequests = OsgiUtil.toInteger(
                 componentConfig.get(PROP_MAX_RECORD_REQUESTS),
                 RequestHistoryConsolePlugin.STORED_REQUESTS_COUNT);
-            RequestHistoryConsolePlugin.initPlugin(bundleContext, maxRequests);
+            String[] patterns = OsgiUtil.toStringArray(componentConfig.get(PROP_TRACK_PATTERNS_REQUESTS),
new String[0]);
+            List<Pattern> compiledPatterns = new ArrayList<Pattern>(patterns.length);
+            for (String pattern : patterns) {
+                compiledPatterns.add(Pattern.compile(pattern));
+            }
+            RequestHistoryConsolePlugin.initPlugin(bundleContext, maxRequests, compiledPatterns);
         } catch (Throwable t) {
             log.debug(
                 "Unable to register web console request recorder plugin.", t);

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java?rev=1183418&r1=1183417&r2=1183418&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
Fri Oct 14 16:47:34 2011
@@ -27,6 +27,7 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Pattern;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -70,9 +71,9 @@ public class RequestHistoryConsolePlugin
         }
     }
 
-    public static void initPlugin(BundleContext context, int maxRequests) {
+    public static void initPlugin(BundleContext context, int maxRequests, List<Pattern>
storePatterns) {
         if (instance == null) {
-            Plugin tmp = new Plugin(maxRequests);
+            Plugin tmp = new Plugin(maxRequests, storePatterns);
             final Dictionary<String, Object> props = new Hashtable<String, Object>();
             props.put(Constants.SERVICE_DESCRIPTION,
                 "Web Console Plugin to display information about recent Sling requests");
@@ -104,11 +105,14 @@ public class RequestHistoryConsolePlugin
     public static final class Plugin extends HttpServlet {
 
         private final RequestInfoMap requests;
+        
+        private final List<Pattern> storePatterns;
 
-        Plugin(int maxRequests) {
-            requests = (maxRequests > 0)
+        Plugin(int maxRequests, List<Pattern> storePatterns) {
+            this.requests = (maxRequests > 0)
                     ? new RequestInfoMap(maxRequests)
                     : null;
+            this.storePatterns = storePatterns;
         }
 
         public void deactivate() {
@@ -122,9 +126,23 @@ public class RequestHistoryConsolePlugin
 
         private void addRequest(SlingHttpServletRequest r) {
             if (requests != null) {
-                synchronized (requests) {
-                    RequestInfo info = new RequestInfo(r);
-                    requests.put(info.getKey(), info);
+                String requestPath = r.getPathInfo();
+                boolean accept = true;
+                if (storePatterns != null && storePatterns.size() > 0) {
+                    accept = false;
+                    for (Pattern pattern : storePatterns) {
+                        if (pattern.matcher(requestPath).matches()) {
+                            accept = true;
+                            break;
+                        }
+                    }
+                }
+
+                if (accept) {
+                    synchronized (requests) {
+                        RequestInfo info = new RequestInfo(r);
+                        requests.put(info.getKey(), info);
+                    }
                 }
             }
         }

Modified: sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1183418&r1=1183417&r2=1183418&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/bundles/engine/src/main/resources/OSGI-INF/metatype/metatype.properties Fri
Oct 14 16:47:34 2011
@@ -50,6 +50,9 @@ sling.max.record.requests.description = 
  internally recorded for display on the "Recent Requests" Web Console page. If \
  this value is less than or equal to zero, no requests are internally kept. The \
  default value is 20. 
+sling.store.pattern.requests.name = Recorded Request Path Patterns
+sling.store.pattern.requests.description = One or more regular expressions which \
+ limit the requests which are stored by the "Recent Requests" Web Console page.
 sling.filter.compat.mode.name = Filter Compat Mode
 sling.filter.compat.mode.description = This switch controls the handling of \
  servlet filters. By default only filters with a scope property are registered. \



Mime
View raw message