You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2026/08/04 15:12:55 UTC

(santuario-xml-security-java) branch main updated: Switch to Jetty 12 for JDK17+ using profiles (#641)

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

coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/santuario-xml-security-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 05bebec5 Switch to Jetty 12 for JDK17+ using profiles (#641)
05bebec5 is described below

commit 05bebec5d9bd36144f9f11b313153dc5148021b2
Author: Colm O hEigeartaigh <co...@users.noreply.github.com>
AuthorDate: Tue Aug 4 16:12:50 2026 +0100

    Switch to Jetty 12 for JDK17+ using profiles (#641)
---
 pom.xml                                            | 73 ++++++++++++++++------
 .../stax/utils/HttpRequestRedirectorProxy.java     | 52 ++++++++++++---
 2 files changed, 98 insertions(+), 27 deletions(-)

diff --git a/pom.xml b/pom.xml
index cd8e4472..b63bfc05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -94,7 +94,8 @@
         <commons.codec.version>1.22.1</commons.codec.version>
         <hamcrest.version>3.0</hamcrest.version>
         <jaxb.runtime>4.0.9</jaxb.runtime>
-        <jetty.version>11.0.24</jetty.version>
+        <jetty11.version>11.0.24</jetty11.version>
+        <jetty12.version>12.0.18</jetty12.version>
         <jmh.version>1.37</jmh.version>
         <junit.version>5.14.4</junit.version>
         <slf4j.version>2.0.18</slf4j.version>
@@ -195,24 +196,6 @@
             <version>${slf4j.version}</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-server</artifactId>
-            <version>${jetty.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-servlet</artifactId>
-            <version>${jetty.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-servlets</artifactId>
-            <version>${jetty.version}</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>xalan</groupId>
             <artifactId>xalan</artifactId>
@@ -764,5 +747,57 @@
                 </dependency>
             </dependencies>
         </profile>
+        <profile>
+            <id>jetty11-jdk11</id>
+            <activation>
+                <jdk>[11,17)</jdk>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.eclipse.jetty</groupId>
+                    <artifactId>jetty-server</artifactId>
+                    <version>${jetty11.version}</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.eclipse.jetty</groupId>
+                    <artifactId>jetty-servlet</artifactId>
+                    <version>${jetty11.version}</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.eclipse.jetty</groupId>
+                    <artifactId>jetty-servlets</artifactId>
+                    <version>${jetty11.version}</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>jetty12-jdk17-plus</id>
+            <activation>
+                <jdk>[17,)</jdk>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.eclipse.jetty</groupId>
+                    <artifactId>jetty-server</artifactId>
+                    <version>${jetty12.version}</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.eclipse.jetty.ee10</groupId>
+                    <artifactId>jetty-ee10-servlet</artifactId>
+                    <version>${jetty12.version}</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.eclipse.jetty.ee10</groupId>
+                    <artifactId>jetty-ee10-servlets</artifactId>
+                    <version>${jetty12.version}</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
     </profiles>
 </project>
diff --git a/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java b/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java
index 53d7bcf9..c6710db7 100644
--- a/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java
+++ b/src/test/java/org/apache/xml/security/test/stax/utils/HttpRequestRedirectorProxy.java
@@ -27,6 +27,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.System.Logger;
 import java.lang.System.Logger.Level;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.Proxy;
@@ -37,8 +40,6 @@ import java.util.List;
 import org.apache.xml.security.stax.ext.XMLSecurityUtils;
 import org.eclipse.jetty.http.MimeTypes;
 import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
 
 /**
  */
@@ -47,6 +48,7 @@ public class HttpRequestRedirectorProxy {
 
     private static final int startPort = 31280;
     private static Server httpServer;
+    private static final String JETTY_SERVLET_PACKAGE = resolveJettyServletPackage();
 
     public static Proxy startHttpEngine() throws Exception {
 
@@ -68,17 +70,17 @@ public class HttpRequestRedirectorProxy {
         resourceHandler.setResourceBase(".");
         httpServer.setHandler(resourceHandler);*/
 
-        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
-        context.setContextPath("/");
-        httpServer.setHandler(context);
-        context.addServlet(new ServletHolder(new TestingHttpProxyServlet()), "/*");
-        httpServer.start();
+        Object context = newJettyServletContextHandler();
+        invoke(context, "setContextPath", new Class<?>[] {String.class}, "/");
+        invoke(httpServer, "setHandler", new Class<?>[] {Class.forName("org.eclipse.jetty.server.Handler")}, context);
+        addServlet(context, new TestingHttpProxyServlet(), "/*");
+        invoke(httpServer, "start");
 
         return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port));
     }
 
     public static void stopHttpEngine() throws Exception {
-        httpServer.stop();
+        invoke(httpServer, "stop");
     }
 
     static class TestingHttpProxyServlet extends HttpServlet {
@@ -116,4 +118,38 @@ public class HttpRequestRedirectorProxy {
             resp.sendError(HttpServletResponse.SC_NOT_FOUND);
         }
     }
+
+    private static String resolveJettyServletPackage() {
+        try {
+            Class.forName("org.eclipse.jetty.ee10.servlet.ServletContextHandler");
+            return "org.eclipse.jetty.ee10.servlet";
+        } catch (ClassNotFoundException ex) {
+            return "org.eclipse.jetty.servlet";
+        }
+    }
+
+    private static Object newJettyServletContextHandler() throws Exception {
+        Class<?> contextClass = Class.forName(JETTY_SERVLET_PACKAGE + ".ServletContextHandler");
+        Field noSessionsField = contextClass.getField("NO_SESSIONS");
+        Constructor<?> constructor = contextClass.getConstructor(int.class);
+        return constructor.newInstance(noSessionsField.getInt(null));
+    }
+
+    private static void addServlet(Object context, HttpServlet servlet, String pathSpec) throws Exception {
+        Class<?> holderClass = Class.forName(JETTY_SERVLET_PACKAGE + ".ServletHolder");
+        Constructor<?> holderConstructor = holderClass.getConstructor(Class.forName("jakarta.servlet.Servlet"));
+        Object servletHolder = holderConstructor.newInstance(servlet);
+        Method addServletMethod = context.getClass().getMethod("addServlet", holderClass, String.class);
+        addServletMethod.invoke(context, servletHolder, pathSpec);
+    }
+
+    private static Object invoke(Object target, String methodName) throws Exception {
+        Method method = target.getClass().getMethod(methodName);
+        return method.invoke(target);
+    }
+
+    private static Object invoke(Object target, String methodName, Class<?>[] parameterTypes, Object... arguments) throws Exception {
+        Method method = target.getClass().getMethod(methodName, parameterTypes);
+        return method.invoke(target, arguments);
+    }
 }