Author: cziegeler Date: Tue Sep 22 13:30:01 2009 New Revision: 817655 URL: http://svn.apache.org/viewvc?rev=817655&view=rev Log: SLING-1119 : First implementation for a filter configuration printer.
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/filter/SlingFilterChainHelper.java 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=817655&r1=817654&r2=817655&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 Tue Sep 22 13:30:01 2009 @@ -47,6 +47,7 @@ import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; +import org.apache.felix.webconsole.ConfigurationPrinter; import org.apache.sling.api.SlingException; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; @@ -90,6 +91,7 @@ * * @scr.component immediate="true" label="%sling.name" * description="%sling.description" + * @scr.service interface="ConfigurationPrinter" * @scr.property name="service.vendor" value="The Apache Software Foundation" * @scr.property name="service.description" value="Sling Servlet" * @scr.reference name="Filter" interface="javax.servlet.Filter" @@ -97,7 +99,7 @@ */ @SuppressWarnings("serial") public class SlingMainServlet extends GenericServlet implements ErrorHandler, - HttpContext { + HttpContext, ConfigurationPrinter { /** @scr.property valueRef="RequestData.DEFAULT_MAX_CALL_COUNTER" */ public static final String PROP_MAX_CALL_COUNTER = "sling.max.calls"; @@ -879,4 +881,42 @@ return oldThreadName; } + /** + * 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) { + if ( entries == null ) { + pw.println("---"); + } else { + for(final SlingFilterChainHelper.FilterListEntry entry : entries) { + pw.print(entry.getOrder()); + pw.print(" : "); + pw.print(entry.getFilter().getClass()); + pw.print(" ("); + pw.print(entry.getFitlerId()); + pw.println(")"); + } + } + } + /** + * Print out the servlet filter chains. + * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter) + */ + public void printConfiguration(PrintWriter pw) { + pw.println("Current Apache Sling Servlet Filter Configuration"); + pw.println(); + pw.println("Request Filters:"); + printFilterChain(pw, this.requestFilterChain.getFilterListEntries()); + pw.println(); + pw.println("Component Filters:"); + printFilterChain(pw, this.innerFilterChain.getFilterListEntries()); + } } Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/SlingFilterChainHelper.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/SlingFilterChainHelper.java?rev=817655&r1=817654&r2=817655&view=diff ============================================================================== --- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/SlingFilterChainHelper.java (original) +++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/filter/SlingFilterChainHelper.java Tue Sep 22 13:30:01 2009 @@ -26,7 +26,7 @@ /** * The <code>SlingFilterChainHelper</code> class is used by Sling to - * support building lists of <code>RenderFilter</code>s. To ensure filter + * support building lists of <code>Filter</code>s. To ensure filter * ordering, each filter is optionally registered with an ordering index. If * none is provided the default ordering index is Integer.MAX_VALUE to append * the filter to the end of the list. @@ -95,7 +95,7 @@ } /** - * Returns the list of <code>RenderFilter</code>s added to this instance + * Returns the list of <code>Filter</code>s added to this instance * or <code>null</code> if no filters have been added. */ public synchronized Filter[] getFilters() { @@ -113,7 +113,20 @@ return filters; } - private static class FilterListEntry implements Comparable<FilterListEntry> { + /** + * Returns the list of <code>FilterListEntry</code>s added to this instance + * or <code>null</code> if no filters have been added. + */ + public synchronized FilterListEntry[] getFilterListEntries() { + FilterListEntry[] result = null; + if (filterList != null && !filterList.isEmpty()) { + result = new FilterListEntry[filterList.size()]; + filterList.toArray(result); + } + return result; + } + + public static class FilterListEntry implements Comparable<FilterListEntry> { private Filter filter; @@ -127,14 +140,18 @@ this.order = order; } - Filter getFilter() { + public Filter getFilter() { return filter; } - Long getFitlerId() { + public Long getFitlerId() { return filterId; } + public int getOrder() { + return order; + } + /** * Note: this class has a natural ordering that is inconsistent with * equals.