incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r783056 - in /incubator/sling/trunk/bundles/engine: ./ src/main/java/org/apache/sling/engine/impl/ src/main/java/org/apache/sling/engine/impl/request/
Date Tue, 09 Jun 2009 16:13:20 GMT
Author: bdelacretaz
Date: Tue Jun  9 16:13:20 2009
New Revision: 783056

URL: http://svn.apache.org/viewvc?rev=783056&view=rev
Log:
SLING-1000 - Web console plugin to display recent requests

Added:
    incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
  (with props)
Modified:
    incubator/sling/trunk/bundles/engine/pom.xml
    incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
    incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
    incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java

Modified: incubator/sling/trunk/bundles/engine/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/pom.xml?rev=783056&r1=783055&r2=783056&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/engine/pom.xml (original)
+++ incubator/sling/trunk/bundles/engine/pom.xml Tue Jun  9 16:13:20 2009
@@ -68,6 +68,9 @@
                             javax.portlet;resolution:=optional,
                             *
                         </Import-Package>
+                        <DynamicImport-Package>
+                            org.apache.felix.webconsole
+                        </DynamicImport-Package>
                         <Bundle-Activator>
                             org.apache.sling.engine.impl.EngineBundleActivator
                         </Bundle-Activator>
@@ -136,6 +139,11 @@
             <artifactId>org.osgi.compendium</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+            <version>1.2.0</version>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>

Modified: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java?rev=783056&r1=783055&r2=783056&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
(original)
+++ incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
Tue Jun  9 16:13:20 2009
@@ -22,6 +22,7 @@
 import java.util.Hashtable;
 
 import org.apache.sling.engine.SlingSettingsService;
+import org.apache.sling.engine.impl.request.RequestHistoryConsolePlugin;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -50,6 +51,7 @@
         serviceRegistration = context.registerService(SlingSettingsService.class.getName(),
                                                       service,
                                                       props);
+        RequestHistoryConsolePlugin.initPlugin(context);
     }
 
     /**
@@ -60,5 +62,6 @@
             serviceRegistration.unregister();
             serviceRegistration = null;
         }
+        RequestHistoryConsolePlugin.destroyPlugin();
     }
 }

Modified: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java?rev=783056&r1=783055&r2=783056&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
(original)
+++ incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingHttpServletRequestImpl.java
Tue Jun  9 16:13:20 2009
@@ -49,6 +49,7 @@
 import org.apache.sling.engine.impl.helper.NullResourceBundle;
 import org.apache.sling.engine.impl.parameters.ParameterSupport;
 import org.apache.sling.engine.impl.request.RequestData;
+import org.apache.sling.engine.impl.request.RequestHistoryConsolePlugin;
 import org.apache.sling.engine.impl.request.SlingRequestDispatcher;
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.useradmin.Authorization;
@@ -74,6 +75,7 @@
             pathInfo = pathInfo.concat(servletRequest.getPathInfo());
         }
         this.pathInfo = pathInfo;
+        RequestHistoryConsolePlugin.recordRequest(this);
     }
 
     /**

Modified: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java?rev=783056&r1=783055&r2=783056&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
(original)
+++ incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
Tue Jun  9 16:13:20 2009
@@ -182,6 +182,10 @@
             servletResponse);
 
         this.requestProgressTracker = new SlingRequestProgressTracker();
+        this.requestProgressTracker.log(
+        		"Method=" +  this.slingRequest.getMethod()
+        		+ ", PathInfo=" + this.slingRequest.getPathInfo()
+        );
     }
 
     public Resource initResource(ResourceResolver resourceResolver) {

Added: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java?rev=783056&view=auto
==============================================================================
--- incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
(added)
+++ incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
Tue Jun  9 16:13:20 2009
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.engine.impl.request;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Felix OSGi console plugin that displays info about recent requests processed
+ * by Sling. Info about all requests can be found in the logs, but this is
+ * useful when testing or explaining things.
+ */
+@SuppressWarnings("serial")
+public class RequestHistoryConsolePlugin extends AbstractWebConsolePlugin {
+
+  public static final String LABEL = "requests";
+  public static final String INDEX = "index";
+  private static RequestHistoryConsolePlugin instance;
+  private ServiceRegistration serviceRegistration;
+
+  public static final int STORED_REQUESTS_COUNT = 20;
+  private final SlingHttpServletRequest[] requests = new SlingHttpServletRequest[STORED_REQUESTS_COUNT];
+  private int lastRequestIndex = -1;
+
+  private RequestHistoryConsolePlugin() {
+  }
+
+  public static void recordRequest(SlingHttpServletRequest r) {
+    if (instance == null) {
+      return;
+    }
+    instance.addRequest(r);
+  }
+
+  private synchronized void addRequest(SlingHttpServletRequest r) {
+    int index = lastRequestIndex + 1;
+    if (index >= requests.length) {
+      index = 0;
+    }
+    requests[index] = r;
+    lastRequestIndex = index;
+  }
+
+  public static void initPlugin(BundleContext context) {
+    if (instance == null) {
+      RequestHistoryConsolePlugin tmp = new RequestHistoryConsolePlugin();
+      tmp.activate(context);
+      instance = tmp;
+    }
+  }
+
+  public static void destroyPlugin() {
+    if (instance != null) {
+      try {
+        instance.deactivate();
+      } finally {
+        instance = null;
+      }
+    }
+  }
+
+  public void activate(BundleContext context) {
+    super.activate(context);
+
+    Dictionary<String, Object> props = new Hashtable<String, Object>();
+    props
+        .put(Constants.SERVICE_DESCRIPTION,
+            "Web Console Plugin to display information about recent Sling requests");
+    props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+    props.put(Constants.SERVICE_PID, getClass().getName());
+    props.put(WebConsoleConstants.PLUGIN_LABEL, LABEL);
+
+    serviceRegistration = context.registerService(
+        WebConsoleConstants.SERVICE_NAME, this, props);
+  }
+
+  public void deactivate() {
+    if (serviceRegistration != null) {
+      serviceRegistration.unregister();
+      serviceRegistration = null;
+    }
+    super.deactivate();
+  }
+
+  @Override
+  public String getLabel() {
+    return LABEL;
+  }
+
+  @Override
+  public String getTitle() {
+    return "Recent requests";
+  }
+
+  @Override
+  protected void renderContent(HttpServletRequest req, HttpServletResponse res)
+      throws ServletException, IOException {
+
+    // Select request to display
+    int index = 0;
+    final String tmp = req.getParameter(INDEX);
+    if (tmp != null) {
+      try {
+        index = Integer.parseInt(tmp);
+      } catch (NumberFormatException ignore) {
+        // ignore
+      }
+    }
+
+    // index is relative to lastRequestIndex
+    int arrayIndex = lastRequestIndex - index;
+    if (arrayIndex < 0) {
+      arrayIndex += requests.length;
+    }
+
+    SlingHttpServletRequest r = null;
+    try {
+      r = requests[arrayIndex];
+    } catch (ArrayIndexOutOfBoundsException ignore) {
+      // ignore
+    }
+
+    final PrintWriter pw = res.getWriter();
+
+    pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
+
+    // Links to other requests
+    pw.println("<thead>");
+    pw.println("<tr class='content'>");
+    pw.println("<th colspan='2'class='content container'>Recent Requests</th>");
+    pw.println("</thead>");
+    pw.println("<tbody>");
+    pw.println("<tr class='content'><td>");
+    for (int i = 0; i < requests.length; i++) {
+      if (requests[i] != null) {
+        final String info = (i == 0 ? " (latest)" : "");
+        pw.print("<a href='" + LABEL + "?index=" + i + "'>");
+        if (i == index) {
+          pw.print("<b>");
+        }
+        pw.print("Request&nbsp;" + i + info);
+        if (i == index) {
+          pw.print("</b>");
+        }
+        pw.println("</a> ");
+      }
+    }
+    pw.println("</td></tr>");
+
+    if (r != null) {
+      // Request Progress Tracker Info
+      pw.println("<tr class='content'>");
+      pw.println("<th colspan='2'class='content container'>");
+      pw.print("Request " + index + " - RequestProgressTracker Info");
+      pw.println("</th></tr>");
+      pw.println("<tr><td colspan='2'>");
+      final Iterator<String> it = r.getRequestProgressTracker().getMessages();
+      pw.print("<pre>");
+      while (it.hasNext()) {
+        pw.print(it.next());
+      }
+      pw.println("</pre></td></tr>");
+    }
+    pw.println("</tbody></table>");
+  }
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message