From 0e5bc9d57ded7b41bd4a663a42f4d36ec62636a9 Mon Sep 17 00:00:00 2001
From: gregw
Date: Thu, 23 May 2024 10:27:49 +1000
Subject: [PATCH] merged ee10 to ee11
---
.../jetty/ee11/servlet/AsyncContextEvent.java | 6 +-
.../ee11/webapp/AbstractConfiguration.java | 28 ++--
.../jetty/ee11/webapp/ClassMatcher.java | 65 --------
.../jetty/ee11/webapp/Configuration.java | 13 +-
.../jetty/ee11/webapp/WebAppClassLoader.java | 1 -
.../jetty/ee11/webapp/WebAppContext.java | 144 ++----------------
.../jetty/ee11/webapp/WebAppContextTest.java | 40 +++--
7 files changed, 59 insertions(+), 238 deletions(-)
delete mode 100644 jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/ClassMatcher.java
diff --git a/jetty-ee11/jetty-ee11-servlet/src/main/java/org/eclipse/jetty/ee11/servlet/AsyncContextEvent.java b/jetty-ee11/jetty-ee11-servlet/src/main/java/org/eclipse/jetty/ee11/servlet/AsyncContextEvent.java
index af6730104447..e70ae134eab7 100644
--- a/jetty-ee11/jetty-ee11-servlet/src/main/java/org/eclipse/jetty/ee11/servlet/AsyncContextEvent.java
+++ b/jetty-ee11/jetty-ee11-servlet/src/main/java/org/eclipse/jetty/ee11/servlet/AsyncContextEvent.java
@@ -20,6 +20,7 @@
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import org.eclipse.jetty.http.HttpURI;
+import org.eclipse.jetty.util.ExceptionUtil;
import org.eclipse.jetty.util.thread.Scheduler;
public class AsyncContextEvent extends AsyncEvent implements Runnable
@@ -149,9 +150,6 @@ public void run()
public void addThrowable(Throwable e)
{
- if (_throwable == null)
- _throwable = e;
- else if (e != _throwable)
- _throwable.addSuppressed(e);
+ _throwable = ExceptionUtil.combine(_throwable, e);
}
}
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/AbstractConfiguration.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/AbstractConfiguration.java
index db7eb34ff409..aa1fe480476f 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/AbstractConfiguration.java
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/AbstractConfiguration.java
@@ -19,13 +19,15 @@
import java.util.Collections;
import java.util.List;
+import org.eclipse.jetty.util.ClassMatcher;
+
public class AbstractConfiguration implements Configuration
{
private final boolean _enabledByDefault;
private final List _after;
private final List _before;
- private final ClassMatcher _system;
- private final ClassMatcher _server;
+ private final ClassMatcher _protected;
+ private final ClassMatcher _hidden;
public static class Builder
{
@@ -88,7 +90,7 @@ public Builder addDependents(Class>... classes)
/**
* Protect classes from modification by the web application by adding them
- * to the {@link WebAppConfiguration#getSystemClasses()}
+ * to the {@link WebAppConfiguration#getProtectedClasses()}
*
* @param classes classname or package pattern
*/
@@ -100,7 +102,7 @@ public Builder protect(String... classes)
/**
* Hide classes from the web application by adding them
- * to the {@link WebAppConfiguration#getServerClasses()}
+ * to the {@link WebAppConfiguration#getHiddenClasses()}
*
* @param classes classname or package pattern
*/
@@ -112,7 +114,7 @@ public Builder hide(String... classes)
/**
* Expose classes to the web application by adding them
- * as exclusions to the {@link WebAppConfiguration#getServerClasses()}
+ * as exclusions to the {@link WebAppConfiguration#getHiddenClasses()}
*
* @param classes classname or package pattern
*/
@@ -129,9 +131,9 @@ public Builder expose(String... classes)
/**
* Protect classes from modification by the web application by adding them
- * to the {@link WebAppConfiguration#getSystemClasses()} and
+ * to the {@link WebAppConfiguration#getProtectedClasses()} and
* expose them to the web application by adding them
- * as exclusions to the {@link WebAppConfiguration#getServerClasses()}
+ * as exclusions to the {@link WebAppConfiguration#getHiddenClasses()}
*
* @param classes classname or package pattern
*/
@@ -154,8 +156,8 @@ protected AbstractConfiguration(Builder builder)
_enabledByDefault = builder._enabledByDefault;
_after = List.copyOf(builder._after);
_before = List.copyOf(builder._before);
- _system = new ClassMatcher(builder._system).asImmutable();
- _server = new ClassMatcher(builder._server).asImmutable();
+ _protected = new ClassMatcher(builder._system).asImmutable();
+ _hidden = new ClassMatcher(builder._server).asImmutable();
}
@Override
@@ -171,15 +173,15 @@ public Collection getDependencies()
}
@Override
- public ClassMatcher getSystemClasses()
+ public ClassMatcher getProtectedClasses()
{
- return _system;
+ return _protected;
}
@Override
- public ClassMatcher getServerClasses()
+ public ClassMatcher getHiddenClasses()
{
- return _server;
+ return _hidden;
}
@Override
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/ClassMatcher.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/ClassMatcher.java
deleted file mode 100644
index 8baa51ccf1ac..000000000000
--- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/ClassMatcher.java
+++ /dev/null
@@ -1,65 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
-//
-// This program and the accompanying materials are made available under the
-// terms of the Eclipse Public License v. 2.0 which is available at
-// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
-// which is available at https://www.apache.org/licenses/LICENSE-2.0.
-//
-// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
-// ========================================================================
-//
-
-package org.eclipse.jetty.ee11.webapp;
-
-import java.net.URI;
-import java.util.Map;
-
-import org.eclipse.jetty.util.IncludeExcludeSet;
-
-/**
- * @deprecated Use org.eclipse.jetty.util.ClassMatcher
- */
-
-@Deprecated(since = "12.0.8", forRemoval = true)
-public class ClassMatcher extends org.eclipse.jetty.util.ClassMatcher
-{
- public ClassMatcher()
- {
- super();
- }
-
- public ClassMatcher(ClassMatcher patterns)
- {
- super(patterns);
- }
-
- public ClassMatcher(org.eclipse.jetty.util.ClassMatcher patterns)
- {
- super(patterns);
- }
-
- public ClassMatcher(String... patterns)
- {
- super(patterns);
- }
-
- public ClassMatcher(String pattern)
- {
- super(pattern);
- }
-
- protected ClassMatcher(Map entries, IncludeExcludeSet patterns, IncludeExcludeSet locations)
- {
- super(entries, patterns, locations);
- }
-
- @Override
- public ClassMatcher asImmutable()
- {
- return new ClassMatcher(Map.copyOf(_entries),
- _patterns.asImmutable(),
- _locations.asImmutable());
- }
-}
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/Configuration.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/Configuration.java
index e2f1957f43ff..23b592f5d88b 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/Configuration.java
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/Configuration.java
@@ -17,6 +17,7 @@
import java.util.Collections;
import java.util.ServiceLoader;
+import org.eclipse.jetty.util.ClassMatcher;
import org.eclipse.jetty.util.TopologicalSort;
/**
@@ -43,8 +44,8 @@
* (eg {@link JndiConfiguration}, {@link JaasConfiguration}} etc.) can be added or removed without concern
* for ordering.
*
- * Also since Jetty-9.4, Configurations are responsible for providing {@link #getServerClasses()} and
- * {@link #getSystemClasses()} to configure the {@link WebAppClassLoader} for each context.
+ *
Also since Jetty-9.4, Configurations are responsible for providing {@link #getHiddenClasses()} and
+ * {@link #getProtectedClasses()} to configure the {@link WebAppClassLoader} for each context.
*
*/
public interface Configuration
@@ -93,21 +94,21 @@ default Collection getDependents()
}
/**
- * Get the system classes associated with this Configuration.
+ * Get the system (protected) classes associated with this Configuration.
*
* @return ClassMatcher of system classes.
*/
- default ClassMatcher getSystemClasses()
+ default ClassMatcher getProtectedClasses()
{
return new ClassMatcher();
}
/**
- * Get the system classes associated with this Configuration.
+ * Get the server (hidden) classes associated with this Configuration.
*
* @return ClassMatcher of server classes.
*/
- default ClassMatcher getServerClasses()
+ default ClassMatcher getHiddenClasses()
{
return new ClassMatcher();
}
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java
index 6558fbfa1e7e..da46960c5387 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppClassLoader.java
@@ -521,7 +521,6 @@ protected Class> loadAsResource(final String name, boolean checkSystemResource
if (webappUrl != null && (!checkSystemResource || !_context.isProtectedResource(name, webappUrl)))
{
-
webappClass = this.foundClass(name, webappUrl);
resolveClass(webappClass);
if (LOG.isDebugEnabled())
diff --git a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java
index 5d401934cc50..c2bd0ef0465b 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java
+++ b/jetty-ee11/jetty-ee11-webapp/src/main/java/org/eclipse/jetty/ee11/webapp/WebAppContext.java
@@ -98,20 +98,6 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
private static final String[] __dftProtectedTargets = {"/WEB-INF", "/META-INF"};
- /**
- * @deprecated use {@link WebAppClassLoading#DEFAULT_PROTECTED_CLASSES}
- */
- @Deprecated (forRemoval = true, since = "12.0.9")
- public static final org.eclipse.jetty.ee11.webapp.ClassMatcher __dftSystemClasses =
- new org.eclipse.jetty.ee11.webapp.ClassMatcher(WebAppClassLoading.DEFAULT_PROTECTED_CLASSES);
-
- /**
- * @deprecated use {@link WebAppClassLoading#DEFAULT_HIDDEN_CLASSES}
- */
- @Deprecated (forRemoval = true, since = "12.0.9")
- public static final org.eclipse.jetty.ee11.webapp.ClassMatcher __dftServerClasses =
- new org.eclipse.jetty.ee11.webapp.ClassMatcher(WebAppClassLoading.DEFAULT_HIDDEN_CLASSES);
-
private final ClassMatcher _protectedClasses = new ClassMatcher(WebAppClassLoading.getProtectedClasses(ServletContextHandler.ENVIRONMENT));
private final ClassMatcher _hiddenClasses = new ClassMatcher(WebAppClassLoading.getHiddenClasses(ServletContextHandler.ENVIRONMENT));
@@ -428,7 +414,7 @@ public void preConfigure() throws Exception
// Add the known server class inclusions for all known configurations
for (Configuration configuration : Configurations.getKnown())
{
- _hiddenClasses.include(configuration.getServerClasses().getInclusions());
+ _hiddenClasses.include(configuration.getHiddenClasses().getInclusions());
}
// Setup Configuration classes for this webapp!
@@ -436,8 +422,8 @@ public void preConfigure() throws Exception
_configurations.sort();
for (Configuration configuration : _configurations)
{
- _protectedClasses.add(configuration.getSystemClasses().getPatterns());
- _hiddenClasses.exclude(configuration.getServerClasses().getExclusions());
+ _protectedClasses.add(configuration.getProtectedClasses().getPatterns());
+ _hiddenClasses.exclude(configuration.getHiddenClasses().getExclusions());
}
// Configure classloader
@@ -623,9 +609,9 @@ public PermissionCollection getPermissions()
}
/**
- * Set the hidden (aka server) classes patterns.
+ * Set the hidden (server) classes patterns.
*
- * These classes/packages are used to implement the server and are hiddenClasses
+ * These classes/packages are used to implement the server and are hidden
* from the context. If the context needs to load these classes, it must have its
* own copy of them in WEB-INF/lib or WEB-INF/classes.
*
@@ -638,7 +624,7 @@ public void setHiddenClassMatcher(ClassMatcher hiddenClasses)
}
/**
- * Set the protected (aka system) classes patterns.
+ * Set the protected (system) classes patterns.
*
* These classes/packages are provided by the JVM and
* cannot be replaced by classes of the same name from WEB-INF,
@@ -683,7 +669,7 @@ public ClassMatcher getProtectedClassMatcher()
}
/**
- * @return The ClassMatcher used to match Server (hiddenClasses) classes
+ * @return The ClassMatcher used to match Server (hidden) classes
*/
public ClassMatcher getHiddenClassMatcher()
{
@@ -696,7 +682,7 @@ public String[] getProtectedClasses()
return _protectedClasses.getPatterns();
}
- @ManagedAttribute(value = "classes and packages hiddenClasses by the context classloader", readonly = true)
+ @ManagedAttribute(value = "classes and packages hidden by the context classloader", readonly = true)
public String[] getHiddenClasses()
{
return _hiddenClasses.getPatterns();
@@ -726,116 +712,6 @@ public boolean isProtectedResource(String name, URL url)
return _protectedClasses.match(name, url);
}
- /**
- * @deprecated use {@link #setHiddenClassMatcher(ClassMatcher)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public void setServerClassMatcher(ClassMatcher serverClasses)
- {
- _hiddenClasses.clear();
- _hiddenClasses.add(serverClasses.getPatterns());
- }
-
- /**
- * @deprecated use {@link #setProtectedClassMatcher(ClassMatcher)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public void setSystemClassMatcher(ClassMatcher systemClasses)
- {
- _protectedClasses.clear();
- _protectedClasses.add(systemClasses.getPatterns());
- }
-
- /**
- * @deprecated use {@link #addHiddenClassMatcher(ClassMatcher)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public void addServerClassMatcher(ClassMatcher serverClasses)
- {
- _hiddenClasses.add(serverClasses.getPatterns());
- }
-
- /**
- * @deprecated use {@link #addProtectedClassMatcher(ClassMatcher)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public void addSystemClassMatcher(ClassMatcher systemClasses)
- {
- _protectedClasses.add(systemClasses.getPatterns());
- }
-
- /**
- * @deprecated use {@link #getProtectedClassMatcher()}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public ClassMatcher getSystemClassMatcher()
- {
- return _protectedClasses;
- }
-
- /**
- * @deprecated use {@link #getHiddenClassMatcher()}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public ClassMatcher getServerClassMatcher()
- {
- return _hiddenClasses;
- }
-
- /**
- * @deprecated use {@link #getProtectedClasses()}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public String[] getSystemClasses()
- {
- return _protectedClasses.getPatterns();
- }
-
- /**
- * @deprecated use {@link #getHiddenClasses()}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public String[] getServerClasses()
- {
- return _hiddenClasses.getPatterns();
- }
-
- /**
- * @deprecated use {@link #isHiddenClass(Class)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public boolean isServerClass(Class> clazz)
- {
- return _hiddenClasses.match(clazz);
- }
-
- /**
- * @deprecated use {@link #isProtectedClass(Class)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public boolean isSystemClass(Class> clazz)
- {
- return _protectedClasses.match(clazz);
- }
-
- /**
- * @deprecated use {@link #isHiddenResource(String, URL)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public boolean isServerResource(String name, URL url)
- {
- return _hiddenClasses.match(name, url);
- }
-
- /**
- * @deprecated use {@link #isProtectedResource(String, URL)}
- */
- @Deprecated(since = "12.0.8", forRemoval = true)
- public boolean isSystemResource(String name, URL url)
- {
- return _protectedClasses.match(name, url);
- }
-
@Override
public void setServer(Server server)
{
@@ -1590,7 +1466,7 @@ public MetaData getMetaData()
}
/**
- * Add a Server Class pattern to use for all ee9 WebAppContexts.
+ * Add a Server Class pattern to use for all WebAppContexts.
* @param server The {@link Server} instance to add classes to
* @param patterns the patterns to use
* @see #getHiddenClassMatcher()
@@ -1604,7 +1480,7 @@ public static void addServerClasses(Server server, String... patterns)
}
/**
- * Add a System Class pattern to use for all ee9 WebAppContexts.
+ * Add a System Class pattern to use for all WebAppContexts.
* @param server The {@link Server} instance to add classes to
* @param patterns the patterns to use
* @see #getProtectedClassMatcher()
diff --git a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java
index b3ad54ee35c2..bc4a2119ce2e 100644
--- a/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java
+++ b/jetty-ee11/jetty-ee11-webapp/src/test/java/org/eclipse/jetty/ee11/webapp/WebAppContextTest.java
@@ -940,13 +940,13 @@ public void testSetServerPropagation()
}
@Test
- public void testAddServerClasses() throws Exception
+ public void testAddHiddenClasses() throws Exception
{
Server server = newServer();
String testPattern = "org.eclipse.jetty.ee11.webapp.test.";
- WebAppContext.addServerClasses(server, testPattern);
+ WebAppClassLoading.addHiddenClasses(server, testPattern);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
@@ -957,25 +957,30 @@ public void testAddServerClasses() throws Exception
Path warPath = createWar(testPath, "test.war");
context.setBaseResource(context.getResourceFactory().newResource(warPath));
+ // Check context specific
+ context.getHiddenClassMatcher().add("org.context.specific.");
+
server.setHandler(context);
server.start();
- List serverClasses = List.of(context.getHiddenClasses());
- assertThat("Should have environment specific test pattern", serverClasses, hasItem(testPattern));
- assertThat("Should have pattern from defaults", serverClasses, hasItem("org.eclipse.jetty."));
- assertThat("Should have pattern from JaasConfiguration", serverClasses, hasItem("-org.eclipse.jetty.security.jaas."));
+ List hiddenClasses = List.of(context.getHiddenClasses());
+ assertThat("Should have environment specific test pattern", hiddenClasses, hasItem(testPattern));
+ assertThat("Should have pattern from defaults", hiddenClasses, hasItem("org.eclipse.jetty."));
+ assertThat("Should have pattern from JaasConfiguration", hiddenClasses, hasItem("-org.eclipse.jetty.security.jaas."));
for (String defaultServerClass: WebAppClassLoading.DEFAULT_HIDDEN_CLASSES)
- assertThat("Should have default patterns", serverClasses, hasItem(defaultServerClass));
+ assertThat("Should have default patterns", hiddenClasses, hasItem(defaultServerClass));
+
+ assertThat("context API", hiddenClasses, hasItem("org.context.specific."));
}
@Test
- public void testAddSystemClasses() throws Exception
+ public void testAddProtectedClasses() throws Exception
{
Server server = newServer();
String testPattern = "org.eclipse.jetty.ee11.webapp.test.";
- WebAppContext.addSystemClasses(server, testPattern);
+ WebAppClassLoading.addProtectedClasses(server, testPattern);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
@@ -985,15 +990,20 @@ public void testAddSystemClasses() throws Exception
Path warPath = createWar(testPath, "test.war");
context.setBaseResource(context.getResourceFactory().newResource(warPath));
+ // Check context specific
+ context.getProtectedClassMatcher().add("org.context.specific.");
+
server.setHandler(context);
server.start();
- List systemClasses = List.of(context.getProtectedClasses());
- assertThat("Should have environment specific test pattern", systemClasses, hasItem(testPattern));
- assertThat("Should have pattern from defaults", systemClasses, hasItem("javax."));
- assertThat("Should have pattern from defaults", systemClasses, hasItem("jakarta."));
- assertThat("Should have pattern from JaasConfiguration", systemClasses, hasItem("org.eclipse.jetty.security.jaas."));
+ List protectedClasses = List.of(context.getProtectedClasses());
+ assertThat("Should have environment specific test pattern", protectedClasses, hasItem(testPattern));
+ assertThat("Should have pattern from defaults", protectedClasses, hasItem("javax."));
+ assertThat("Should have pattern from defaults", protectedClasses, hasItem("jakarta."));
+ assertThat("Should have pattern from JaasConfiguration", protectedClasses, hasItem("org.eclipse.jetty.security.jaas."));
for (String defaultSystemClass: WebAppClassLoading.DEFAULT_PROTECTED_CLASSES)
- assertThat("Should have default patterns", systemClasses, hasItem(defaultSystemClass));
+ assertThat("Should have default patterns", protectedClasses, hasItem(defaultSystemClass));
+
+ assertThat("context API", protectedClasses, hasItem("org.context.specific."));
}
}