This is an automated email from the ASF dual-hosted git repository. kwin pushed a commit to branch feature/expose-osgi-whiteboard-filters in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-engine.git
commit d275870c8cf6e7cb4794f94169cced547681e8cd Author: Konrad Windszus <[email protected]> AuthorDate: Mon Feb 2 17:55:01 2026 +0100 SLING-13089 Expose OSGi HTTP Whiteboard filters as well --- pom.xml | 6 ++++- .../impl/console/WebConsoleConfigPrinter.java | 31 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 6e42c31..7a3bbb0 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,11 @@ <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.service.http.whiteboard</artifactId> - <version>1.1.1</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.dto</artifactId> <scope>provided</scope> </dependency> <dependency> diff --git a/src/main/java/org/apache/sling/engine/impl/console/WebConsoleConfigPrinter.java b/src/main/java/org/apache/sling/engine/impl/console/WebConsoleConfigPrinter.java index 930e203..c90e855 100644 --- a/src/main/java/org/apache/sling/engine/impl/console/WebConsoleConfigPrinter.java +++ b/src/main/java/org/apache/sling/engine/impl/console/WebConsoleConfigPrinter.java @@ -19,13 +19,17 @@ package org.apache.sling.engine.impl.console; import java.io.PrintWriter; +import java.util.Arrays; +import org.apache.sling.engine.impl.SlingHttpContext; import org.apache.sling.engine.impl.filter.FilterHandle; import org.apache.sling.engine.impl.filter.ServletFilterManager; import org.apache.sling.engine.impl.filter.ServletFilterManager.FilterChainType; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.runtime.HttpServiceRuntime; +import org.osgi.service.http.runtime.dto.ServletContextDTO; /** * This is a configuration printer for the web console which @@ -42,10 +46,32 @@ import org.osgi.service.component.annotations.Reference; public class WebConsoleConfigPrinter { private final ServletFilterManager filterManager; + private final HttpServiceRuntime httpServiceRuntime; @Activate - public WebConsoleConfigPrinter(@Reference final ServletFilterManager filterManager) { + public WebConsoleConfigPrinter( + @Reference final ServletFilterManager filterManager, + @Reference HttpServiceRuntime httpServiceRuntime) { this.filterManager = filterManager; + this.httpServiceRuntime = httpServiceRuntime; + } + + private static boolean isRelevantContext(ServletContextDTO ctx) { + return SlingHttpContext.SERVLET_CONTEXT_NAME.equals(ctx.name); + } + + private void printOsgiHttpWhiteboardFilters(PrintWriter pw, ServletContextDTO ctx) { + pw.println(); + pw.printf("OSGi Http Whiteboard Filters for Context %s%n", ctx.name); + Arrays.stream(ctx.filterDTOs).forEach(filter -> { + pw.printf("Name: %s, Id: %d%n", filter.name, filter.serviceId); + }); + } + + private void printOsgiHttpWhiteboardFilters(PrintWriter pw) { + Arrays.stream(httpServiceRuntime.getRuntimeDTO().servletContextDTOs) + .filter(ctx -> isRelevantContext(ctx)) + .forEach(ctx -> printOsgiHttpWhiteboardFilters(pw, ctx)); } /** @@ -75,9 +101,10 @@ public class WebConsoleConfigPrinter { */ public void printConfiguration(PrintWriter pw) { pw.println("Current Apache Sling Servlet Filter Configuration"); + printOsgiHttpWhiteboardFilters(pw); for (FilterChainType type : FilterChainType.values()) { pw.println(); - pw.println(type + " Filters:"); + pw.println("Sling " + type + " Filters:"); printFilterChain(pw, filterManager.getFilterChain(type).getFilters()); } }
