This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-engine.git


The following commit(s) were added to refs/heads/master by this push:
     new 133fd92  SLING-13089 Expose OSGi HTTP Whiteboard filters in Sling 
Filters web console plugin
133fd92 is described below

commit 133fd920ebf49360e5cc72a30b8742c5057835e2
Author: Konrad Windszus <[email protected]>
AuthorDate: Thu Feb 5 14:34:21 2026 +0100

    SLING-13089 Expose OSGi HTTP Whiteboard filters in Sling Filters web 
console plugin
---
 pom.xml                                            |  6 +-
 .../impl/console/WebConsoleConfigPrinter.java      | 64 +++++++++++++++++++++-
 2 files changed, 67 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..69aa666 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,23 @@
 package org.apache.sling.engine.impl.console;
 
 import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.Collection;
 
+import jakarta.servlet.Filter;
+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.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
 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
@@ -41,11 +51,60 @@ import org.osgi.service.component.annotations.Reference;
         })
 public class WebConsoleConfigPrinter {
 
+    private final BundleContext bundleContext;
     private final ServletFilterManager filterManager;
+    private final HttpServiceRuntime httpServiceRuntime;
 
     @Activate
-    public WebConsoleConfigPrinter(@Reference final ServletFilterManager 
filterManager) {
+    public WebConsoleConfigPrinter(
+            BundleContext bundleContext,
+            @Reference final ServletFilterManager filterManager,
+            @Reference HttpServiceRuntime httpServiceRuntime) {
+        this.bundleContext = bundleContext;
         this.filterManager = filterManager;
+        this.httpServiceRuntime = httpServiceRuntime;
+    }
+
+    private static boolean isRelevantContext(ServletContextDTO ctx) {
+        return SlingHttpContext.SERVLET_CONTEXT_NAME.equals(ctx.name);
+    }
+
+    private String getServiceRanking(long serviceId) {
+        ServiceReference<?> ref = null;
+        try {
+            Collection<ServiceReference<Filter>> refs = 
bundleContext.getServiceReferences(
+                    Filter.class, "(" + Constants.SERVICE_ID + "=" + serviceId 
+ ")");
+            if (refs.isEmpty()) {
+                Collection<ServiceReference<javax.servlet.Filter>> javaxRefs = 
bundleContext.getServiceReferences(
+                        javax.servlet.Filter.class, "(" + Constants.SERVICE_ID 
+ "=" + serviceId + ")");
+                if (!javaxRefs.isEmpty()) {
+                    ref = javaxRefs.iterator().next();
+                }
+            } else {
+                ref = refs.iterator().next();
+            }
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalStateException("Invalid syntax given to lookup 
service", e);
+        }
+        if (ref != null) {
+            Object ranking = ref.getProperty(Constants.SERVICE_RANKING);
+            return ranking != null ? ranking.toString() : "0";
+        }
+        return "?";
+    }
+
+    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("%s : %s (id: %d)%n", 
getServiceRanking(filter.serviceId), 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 +134,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());
         }
     }

Reply via email to