You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/10/11 18:10:34 UTC
svn commit: r1021403 - in /sling/trunk/bundles/engine: ./
src/main/java/org/apache/sling/engine/impl/
src/main/java/org/apache/sling/engine/impl/request/
Author: cziegeler
Date: Mon Oct 11 16:10:33 2010
New Revision: 1021403
URL: http://svn.apache.org/viewvc?rev=1021403&view=rev
Log:
SLING-1834 : Remove direct dependency to web console by using new configuration printer support
Modified:
sling/trunk/bundles/engine/pom.xml
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
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/WebConsoleConfigPrinter.java
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestHistoryConsolePlugin.java
Modified: sling/trunk/bundles/engine/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/pom.xml?rev=1021403&r1=1021402&r2=1021403&view=diff
==============================================================================
--- sling/trunk/bundles/engine/pom.xml (original)
+++ sling/trunk/bundles/engine/pom.xml Mon Oct 11 16:10:33 2010
@@ -72,9 +72,6 @@
javax.portlet;resolution:=optional,
*
</Import-Package>
- <DynamicImport-Package>
- org.apache.felix.webconsole
- </DynamicImport-Package>
<Bundle-Activator>
org.apache.sling.engine.impl.EngineBundleActivator
</Bundle-Activator>
@@ -155,11 +152,6 @@
<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: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java?rev=1021403&r1=1021402&r2=1021403&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java (original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/EngineBundleActivator.java Mon Oct 11 16:10:33 2010
@@ -33,21 +33,13 @@ public class EngineBundleActivator imple
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
- try {
- RequestHistoryConsolePlugin.initPlugin(context);
- } catch (Throwable ignore) {
- // we just ignore this
- }
+ RequestHistoryConsolePlugin.initPlugin(context);
}
/**
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- try {
- RequestHistoryConsolePlugin.destroyPlugin();
- } catch (Throwable ignore) {
- // we just ignore this
- }
+ RequestHistoryConsolePlugin.destroyPlugin();
}
}
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=1021403&r1=1021402&r2=1021403&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 Mon Oct 11 16:10:33 2010
@@ -309,12 +309,8 @@ public class SlingMainServlet extends Ge
// initialize requestListenerManager
requestListenerManager = new RequestListenerManager( bundleContext, slingServletContext );
- // try to setup configuration printer
- try {
- this.printerRegistration = WebConsoleConfigPrinter.register(bundleContext, filterManager);
- } catch (Throwable t) {
- log.debug("Unable to register web console configuration printer.", t);
- }
+ // Setup configuration printer
+ this.printerRegistration = WebConsoleConfigPrinter.register(bundleContext, filterManager);
// provide the SlingRequestProcessor service
Hashtable<String, String> srpProps = new Hashtable<String, String>();
Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java?rev=1021403&r1=1021402&r2=1021403&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java (original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java Mon Oct 11 16:10:33 2010
@@ -22,10 +22,9 @@ import java.io.PrintWriter;
import java.util.Dictionary;
import java.util.Hashtable;
-import org.apache.felix.webconsole.ConfigurationPrinter;
import org.apache.sling.engine.impl.filter.ServletFilterManager;
-import org.apache.sling.engine.impl.filter.SlingFilterChainHelper;
import org.apache.sling.engine.impl.filter.ServletFilterManager.FilterChainType;
+import org.apache.sling.engine.impl.filter.SlingFilterChainHelper;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
@@ -35,7 +34,7 @@ import org.osgi.framework.ServiceRegistr
* prints out the currently configured filter chains.
*
*/
-public class WebConsoleConfigPrinter implements ConfigurationPrinter {
+public class WebConsoleConfigPrinter {
private final ServletFilterManager filterManager;
@@ -57,8 +56,11 @@ public class WebConsoleConfigPrinter imp
serviceProps.put(Constants.SERVICE_DESCRIPTION,
"Apache Sling Servlet Filter Configuration Printer");
serviceProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+ serviceProps.put("felix.webconsole.label", "slingfilter");
+ serviceProps.put("felix.webconsole.title", "Sling Servlet Filter");
+ serviceProps.put("felix.webconsole.configprinter.modes", "always");
- reg.filterPlugin = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+ reg.filterPlugin = bundleContext.registerService(WebConsoleConfigPrinter.class.getName(),
filterPrinter,
serviceProps);
return reg;
@@ -75,14 +77,6 @@ public class WebConsoleConfigPrinter imp
}
/**
- * Return the title for the configuration printer
- * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
- */
- public String getTitle() {
- return "Servlet Filter";
- }
-
- /**
* Helper method for printing out a filter chain.
*/
private void printFilterChain(final PrintWriter pw, final SlingFilterChainHelper.FilterListEntry[] entries) {
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=1021403&r1=1021402&r2=1021403&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 Mon Oct 11 16:10:33 2010
@@ -27,11 +27,10 @@ import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
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;
@@ -51,6 +50,8 @@ public class RequestHistoryConsolePlugin
private static Plugin instance;
+ private static ServiceRegistration serviceRegistration;
+
public static final int STORED_REQUESTS_COUNT = 20;
private RequestHistoryConsolePlugin() {
@@ -65,7 +66,16 @@ public class RequestHistoryConsolePlugin
public static void initPlugin(BundleContext context) {
if (instance == null) {
Plugin tmp = new Plugin();
- tmp.activate(context);
+ final 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, tmp.getClass().getName());
+ props.put("felix.webconsole.label", LABEL);
+ props.put("felix.webconsole.title", "Recent requests");
+
+ serviceRegistration = context.registerService(
+ "javax.servlet.Servlet", tmp, props);
instance = tmp;
}
}
@@ -73,22 +83,23 @@ public class RequestHistoryConsolePlugin
public static void destroyPlugin() {
if (instance != null) {
try {
- instance.deactivate();
+ if (serviceRegistration != null) {
+ serviceRegistration.unregister();
+ serviceRegistration = null;
+ }
} finally {
instance = null;
}
}
}
- public static final class Plugin extends AbstractWebConsolePlugin {
+ public static final class Plugin extends HttpServlet {
private final SlingHttpServletRequest[] requests = new SlingHttpServletRequest[STORED_REQUESTS_COUNT];
/** Need to store methods separately, apparently requests clear this data when done processing */
private final String [] methods = new String[STORED_REQUESTS_COUNT];
- private ServiceRegistration serviceRegistration;
-
private int lastRequestIndex = -1;
private synchronized void addRequest(SlingHttpServletRequest r) {
@@ -108,38 +119,6 @@ public class RequestHistoryConsolePlugin
lastRequestIndex = -1;
}
- 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";
- }
-
private int getArrayIndex(int displayIndex) {
int result = lastRequestIndex - displayIndex;
if (result < 0) {
@@ -190,13 +169,12 @@ public class RequestHistoryConsolePlugin
}
@Override
- protected void renderContent(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
-
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
// If so requested, clear our data
if(req.getParameter(CLEAR) != null) {
clear();
- res.sendRedirect(LABEL);
+ resp.sendRedirect(LABEL);
return;
}
@@ -221,7 +199,7 @@ public class RequestHistoryConsolePlugin
// ignore
}
- final PrintWriter pw = res.getWriter();
+ final PrintWriter pw = resp.getWriter();
pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");