diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java index 6927c09295e..c2ad63eecbe 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceFactory.java @@ -17,14 +17,17 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.function.Function; -import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.component.Container; import org.eclipse.jetty.util.component.Dumpable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** *

ResourceFactory is the source of new {@link Resource} instances.

@@ -113,6 +116,8 @@ import org.eclipse.jetty.util.component.Dumpable; */ public interface ResourceFactory { + static final Logger LOG = LoggerFactory.getLogger(ResourceFactory.class); + /** *

Make a directory Resource containing a collection of other directory {@link Resource}s

* @param resources multiple directory {@link Resource}s to combine as a single resource. Order is significant. @@ -150,59 +155,80 @@ public interface ResourceFactory Resource newResource(URI uri); /** - *

Construct a system resource from a string.

- * - *

- * The resource is first attempted to be accessed via the {@link Thread#getContextClassLoader()} - * before being treated as a normal resource. - *

+ *

Construct a Resource from a string reference into classloaders.

* * @param resource Resource as string representation * @return The new Resource, or null if string points to a location that does not exist * @throws IllegalArgumentException if string is blank + * @see #newClassLoaderResource(String, boolean) + * @deprecated use {@link #newClassLoaderResource(String)} or {@link #newClassLoaderResource(String, boolean)} instead, will be removed in Jetty 12.1.0 */ + @Deprecated(since = "12.0.2", forRemoval = true) default Resource newSystemResource(String resource) + { + return newClassLoaderResource(resource); + } + + /** + *

Construct a Resource from a search of ClassLoaders.

+ * + *

+ * Search order is: + *

+ *
    + *
  1. {@link ClassLoader#getResource(String) java.lang.Thread.currentThread().getContextClassLoader().getResource(String)}
  2. + *
  3. {@link ClassLoader#getResource(String) ResourceFactory.class.getClassLoader().getResource(String)}
  4. + *
  5. (optional) {@link ClassLoader#getSystemResource(String) java.lang.ClassLoader.getSystemResource(String)}
  6. + *
+ * + *

+ * See {@link ClassLoader#getResource(String)} for rules on resource name parameter. + *

+ * + *

+ * If a provided resource name starts with a {@code /} (example: {@code /org/example/ClassName.class}) + * then the non-slash version is also tried against the same ClassLoader (example: {@code org/example/ClassName.class}). + *

+ * + * @param resource the resource name to find in a classloader + * @param searchSystemClassLoader true to search {@link ClassLoader#getSystemResource(String)}, false to skip + * @return The new Resource, or null if string points to a location that does not exist + * @throws IllegalArgumentException if resource name or resulting URL from ClassLoader is invalid. + */ + default Resource newClassLoaderResource(String resource, boolean searchSystemClassLoader) { if (StringUtil.isBlank(resource)) throw new IllegalArgumentException("Resource String is invalid: " + resource); URL url = null; - // Try to format as a URL? - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - if (loader != null) + + List> loaders = new ArrayList(); + loaders.add(Thread.currentThread().getContextClassLoader()::getResource); + loaders.add(ResourceFactory.class.getClassLoader()::getResource); + if (searchSystemClassLoader) + loaders.add(ClassLoader::getSystemResource); + + for (Function loader : loaders) { + if (url != null) + break; + try { - url = loader.getResource(resource); + url = loader.apply(resource); if (url == null && resource.startsWith("/")) - url = loader.getResource(resource.substring(1)); + url = loader.apply(resource.substring(1)); } catch (IllegalArgumentException e) { // Catches scenario where a bad Windows path like "C:\dev" is // improperly escaped, which various downstream classloaders // tend to have a problem with + if (LOG.isTraceEnabled()) + LOG.trace("Ignoring bad getResource(): {}", resource, e); } } - if (url == null) - { - loader = ResourceFactory.class.getClassLoader(); - if (loader != null) - { - url = loader.getResource(resource); - if (url == null && resource.startsWith("/")) - url = loader.getResource(resource.substring(1)); - } - } - - if (url == null) - { - url = ClassLoader.getSystemResource(resource); - if (url == null && resource.startsWith("/")) - url = ClassLoader.getSystemResource(resource.substring(1)); - } - if (url == null) return null; @@ -218,37 +244,39 @@ public interface ResourceFactory } /** - *

Find a classpath resource.

+ *

Construct a Resource from a search of ClassLoaders.

* *

- * The {@link Class#getResource(String)} method is used to lookup the resource. If it is not - * found, then the {@link Loader#getResource(String)} method is used. + * Convenience method {@code .newClassLoaderResource(resource, true)} + *

+ * + * @param resource string representation of resource to find in a classloader + * @return The new Resource, or null if string points to a location that does not exist + * @throws IllegalArgumentException if string is blank + * @see #newClassLoaderResource(String, boolean) + */ + default Resource newClassLoaderResource(String resource) + { + return newClassLoaderResource(resource, true); + } + + /** + *

Construct a Resource from a search of ClassLoaders.

+ * + *

+ * Convenience method {@code .newClassLoaderResource(resource, false)} *

* * @param resource the relative name of the resource * @return Resource, or null if string points to a location that does not exist * @throws IllegalArgumentException if string is blank + * @see #newClassLoaderResource(String, boolean) + * @deprecated use {@link #newClassLoaderResource(String, boolean)} instead, will be removed in Jetty 12.1.0 */ + @Deprecated(since = "12.0.2", forRemoval = true) default Resource newClassPathResource(String resource) { - if (StringUtil.isBlank(resource)) - throw new IllegalArgumentException("Resource String is invalid: " + resource); - - URL url = ResourceFactory.class.getResource(resource); - - if (url == null) - url = Loader.getResource(resource); - if (url == null) - return null; - try - { - URI uri = url.toURI(); - return newResource(uri); - } - catch (URISyntaxException e) - { - throw new IllegalArgumentException(e); - } + return newClassLoaderResource(resource, false); } /** @@ -266,7 +294,7 @@ public interface ResourceFactory * @param url the URL to load into memory * @return Resource, or null if url points to a location that does not exist * @throws IllegalArgumentException if URL is null - * @see #newClassPathResource(String) + * @see #newClassLoaderResource(String, boolean) */ default Resource newMemoryResource(URL url) { diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java index 5c6738af40a..0157aaa9b60 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java @@ -19,19 +19,116 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ResourceFactoryTest { + @ParameterizedTest + @ValueSource(strings = { + "keystore.p12", "/keystore.p12", + "TestData/alphabet.txt", "/TestData/alphabet.txt", + "TestData/", "/TestData/", "TestData", "/TestData" + }) + public void testNewClassLoaderResourceExists(String reference) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + Resource resource = resourceFactory.newClassLoaderResource(reference); + assertNotNull(resource, "Reference [" + reference + "] should be found"); + assertTrue(resource.exists(), "Reference [" + reference + "] -> Resource[" + resource + "] should exist"); + } + } + + @ParameterizedTest + @ValueSource(strings = {"does-not-exist.dat", "non-existent/dir/contents.txt", "/../"}) + public void testNewClassLoaderResourceDoesNotExists(String reference) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + Resource resource = resourceFactory.newClassLoaderResource(reference); + assertNull(resource, "Reference [" + reference + "] should not be found"); + } + } + + public static List badReferenceNamesSource() + { + List names = new ArrayList<>(); + names.add(null); + names.add(""); + names.add(" "); + names.add("\r"); + names.add("\r\n"); + names.add(" \t "); + return names; + } + + @ParameterizedTest + @MethodSource("badReferenceNamesSource") + public void testNewClassLoaderResourceDoesBadInput(String reference) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + assertThrows(IllegalArgumentException.class, + () -> resourceFactory.newClassLoaderResource(reference), + "Bad Reference [" + reference + "] should have failed"); + } + } + + @ParameterizedTest + @ValueSource(strings = { + "keystore.p12", "/keystore.p12", + "TestData/alphabet.txt", "/TestData/alphabet.txt", + "TestData/", "/TestData/", "TestData", "/TestData" + }) + public void testNewClassPathResourceExists(String reference) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + Resource resource = resourceFactory.newClassPathResource(reference); + assertNotNull(resource, "Reference [" + reference + "] should be found"); + assertTrue(resource.exists(), "Reference [" + reference + "] -> Resource[" + resource + "] should exist"); + } + } + + @ParameterizedTest + @ValueSource(strings = {"does-not-exist.dat", "non-existent/dir/contents.txt", "/../"}) + public void testNewClassPathResourceDoesNotExists(String reference) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + Resource resource = resourceFactory.newClassPathResource(reference); + assertNull(resource, "Reference [" + reference + "] should not be found"); + } + } + + @ParameterizedTest + @MethodSource("badReferenceNamesSource") + public void testNewClassPathResourceDoesBadInput(String reference) + { + try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) + { + assertThrows(IllegalArgumentException.class, + () -> resourceFactory.newClassPathResource(reference), + "Bad Reference [" + reference + "] should have failed"); + } + } + @Test public void testCustomUriSchemeNotRegistered() { diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java index 9cb01e06abd..b2a1c1bb8ec 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java @@ -52,7 +52,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import static org.junit.jupiter.api.Assumptions.assumeTrue; @ExtendWith(WorkDirExtension.class) @@ -455,90 +454,4 @@ public class ResourceTest assertThat(resource.isDirectory(), is(true)); assertThat(resource.length(), is(0L)); } - - /** - * Test a class path resource for existence. - */ - @Test - public void testClassPathResourceClassRelative() - { - final String classPathName = "Resource.class"; - - Resource resource = resourceFactory.newClassPathResource(classPathName); - - // A class path cannot be a directory - assertFalse(resource.isDirectory(), "Class path cannot be a directory."); - - // A class path must exist - assertTrue(resource.exists(), "Class path resource does not exist."); - } - - /** - * Test a class path resource for existence. - */ - @Test - public void testClassPathResourceClassAbsolute() - { - final String classPathName = "/org/eclipse/jetty/util/resource/Resource.class"; - - Resource resource = resourceFactory.newClassPathResource(classPathName); - - // A class path cannot be a directory - assertFalse(resource.isDirectory(), "Class path cannot be a directory."); - - // A class path must exist - assertTrue(resource.exists(), "Class path resource does not exist."); - } - - /** - * Test a class path resource for directories. - * - * @throws Exception failed test - */ - @Test - public void testClassPathResourceDirectory() throws Exception - { - // If the test runs in the module-path, resource "/" cannot be found. - assumeFalse(Resource.class.getModule().isNamed()); - - final String classPathName = "/"; - - Resource resource = resourceFactory.newClassPathResource(classPathName); - - // A class path must be a directory - assertTrue(resource.isDirectory(), "Class path must be a directory."); - - assertTrue(Files.isDirectory(resource.getPath()), "Class path returned file must be a directory."); - - // A class path must exist - assertTrue(resource.exists(), "Class path resource does not exist."); - } - - /** - * Test a class path resource for a file. - * - * @throws Exception failed test - */ - @Test - public void testClassPathResourceFile() throws Exception - { - final String fileName = "resource.txt"; - final String classPathName = "/" + fileName; - - // Will locate a resource in the class path - Resource resource = resourceFactory.newClassPathResource(classPathName); - - // A class path cannot be a directory - assertFalse(resource.isDirectory(), "Class path must be a directory."); - - assertNotNull(resource); - - Path path = resource.getPath(); - - assertEquals(fileName, path.getFileName().toString(), "File name from class path is not equal."); - assertTrue(Files.isRegularFile(path), "File returned from class path should be a regular file."); - - // A class path must exist - assertTrue(resource.exists(), "Class path resource does not exist."); - } } diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java index 5d3319f8bca..23c8d914676 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/SslContextFactoryTest.java @@ -199,7 +199,7 @@ public class SslContextFactoryTest public void testNoTsResourceKs() throws Exception { SslContextFactory.Server cf = new SslContextFactory.Server(); - Resource keystoreResource = ResourceFactory.of(cf).newSystemResource("keystore.p12"); + Resource keystoreResource = ResourceFactory.of(cf).newClassLoaderResource("keystore.p12"); cf.setKeyStoreResource(keystoreResource); cf.setKeyStorePassword("storepwd"); @@ -215,8 +215,8 @@ public class SslContextFactoryTest public void testResourceTsResourceKs() throws Exception { SslContextFactory.Server cf = new SslContextFactory.Server(); - Resource keystoreResource = ResourceFactory.of(cf).newSystemResource("keystore.p12"); - Resource truststoreResource = ResourceFactory.of(cf).newSystemResource("keystore.p12"); + Resource keystoreResource = ResourceFactory.of(cf).newClassLoaderResource("keystore.p12"); + Resource truststoreResource = ResourceFactory.of(cf).newClassLoaderResource("keystore.p12"); cf.setKeyStoreResource(keystoreResource); cf.setKeyStorePassword("storepwd"); @@ -232,8 +232,8 @@ public class SslContextFactoryTest public void testResourceTsWrongPWResourceKs() throws Exception { SslContextFactory.Server cf = new SslContextFactory.Server(); - Resource keystoreResource = ResourceFactory.of(cf).newSystemResource("keystore.p12"); - Resource truststoreResource = ResourceFactory.of(cf).newSystemResource("keystore.p12"); + Resource keystoreResource = ResourceFactory.of(cf).newClassLoaderResource("keystore.p12"); + Resource truststoreResource = ResourceFactory.of(cf).newClassLoaderResource("keystore.p12"); cf.setKeyStoreResource(keystoreResource); cf.setKeyStorePassword("storepwd"); @@ -307,7 +307,7 @@ public class SslContextFactoryTest public void testSNICertificates() throws Exception { SslContextFactory.Server cf = new SslContextFactory.Server(); - Resource keystoreResource = ResourceFactory.of(cf).newSystemResource("snikeystore.p12"); + Resource keystoreResource = ResourceFactory.of(cf).newClassLoaderResource("snikeystore.p12"); cf.setKeyStoreResource(keystoreResource); cf.setKeyStorePassword("storepwd"); @@ -348,14 +348,14 @@ public class SslContextFactoryTest public void testNonDefaultKeyStoreTypeUsedForTrustStore() throws Exception { SslContextFactory.Server cf = new SslContextFactory.Server(); - cf.setKeyStoreResource(ResourceFactory.of(cf).newSystemResource("keystore.p12")); + cf.setKeyStoreResource(ResourceFactory.of(cf).newClassLoaderResource("keystore.p12")); cf.setKeyStoreType("pkcs12"); cf.setKeyStorePassword("storepwd"); cf.start(); cf.stop(); cf = new SslContextFactory.Server(); - cf.setKeyStoreResource(ResourceFactory.of(cf).newSystemResource("keystore.jce")); + cf.setKeyStoreResource(ResourceFactory.of(cf).newClassLoaderResource("keystore.jce")); cf.setKeyStoreType("jceks"); cf.setKeyStorePassword("storepwd"); cf.start(); @@ -401,7 +401,7 @@ public class SslContextFactoryTest } }; // This test requires a SNI keystore so that the X509ExtendedKeyManager is wrapped. - serverTLS.setKeyStoreResource(ResourceFactory.of(serverTLS).newSystemResource("keystore_sni.p12")); + serverTLS.setKeyStoreResource(ResourceFactory.of(serverTLS).newClassLoaderResource("keystore_sni.p12")); serverTLS.setKeyStorePassword("storepwd"); serverTLS.setKeyManagerFactoryAlgorithm("PKIX"); // Don't pick a default certificate if SNI does not match. diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/X509Test.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/X509Test.java index bca31b3bf66..f04e492f9b8 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/X509Test.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/ssl/X509Test.java @@ -163,7 +163,7 @@ public class X509Test public void testServerClassWithoutSni() throws Exception { SslContextFactory serverSsl = new SslContextFactory.Server(); - Resource keystoreResource = ResourceFactory.root().newSystemResource("keystore.p12"); + Resource keystoreResource = ResourceFactory.root().newClassLoaderResource("keystore.p12"); serverSsl.setKeyStoreResource(keystoreResource); serverSsl.setKeyStorePassword("storepwd"); serverSsl.start(); @@ -173,7 +173,7 @@ public class X509Test public void testClientClassWithoutSni() throws Exception { SslContextFactory clientSsl = new SslContextFactory.Client(); - Resource keystoreResource = ResourceFactory.root().newSystemResource("keystore.p12"); + Resource keystoreResource = ResourceFactory.root().newClassLoaderResource("keystore.p12"); clientSsl.setKeyStoreResource(keystoreResource); clientSsl.setKeyStorePassword("storepwd"); clientSsl.start(); diff --git a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ExampleServerXml.java b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ExampleServerXml.java index c7c3f6bb9bc..720875ef925 100644 --- a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ExampleServerXml.java +++ b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ExampleServerXml.java @@ -28,7 +28,7 @@ public class ExampleServerXml // Find Jetty XML (in classpath) that configures and starts Server. // See src/main/resources/exampleserver.xml ResourceFactory.LifeCycle resourceFactory = ResourceFactory.lifecycle(); - Resource serverXml = resourceFactory.newSystemResource("exampleserver.xml"); + Resource serverXml = resourceFactory.newClassLoaderResource("exampleserver.xml"); XmlConfiguration xml = new XmlConfiguration(serverXml); xml.getProperties().put("http.port", Integer.toString(port)); Server server = (Server)xml.configure(); diff --git a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/FileServerXml.java b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/FileServerXml.java index 70dff57c501..5f30472f47d 100644 --- a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/FileServerXml.java +++ b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/FileServerXml.java @@ -35,7 +35,7 @@ public class FileServerXml // Find Jetty XML (in classpath) that configures and starts Server. // See src/main/resources/fileserver.xml ResourceFactory.LifeCycle resourceFactory = ResourceFactory.lifecycle(); - Resource fileServerXml = resourceFactory.newSystemResource("fileserver.xml"); + Resource fileServerXml = resourceFactory.newClassLoaderResource("fileserver.xml"); Resource baseResource = resourceFactory.newResource(basePath); XmlConfiguration configuration = new XmlConfiguration(fileServerXml); configuration.getProperties().put("fileserver.baseResource", baseResource.toString()); diff --git a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/OneWebAppWithJsp.java b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/OneWebAppWithJsp.java index c27b9a31ee5..d0fc81ef3f2 100644 --- a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/OneWebAppWithJsp.java +++ b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/OneWebAppWithJsp.java @@ -77,7 +77,7 @@ public class OneWebAppWithJsp // can be started and stopped according to the lifecycle of the server // itself. String realmResourceName = "etc/realm.properties"; - Resource realmResource = webapp.getResourceFactory().newClassPathResource(realmResourceName); + Resource realmResource = webapp.getResourceFactory().newClassLoaderResource(realmResourceName, false); if (realmResource == null) throw new FileNotFoundException("Unable to find " + realmResourceName); diff --git a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/SecuredHelloHandler.java b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/SecuredHelloHandler.java index dd973440f7d..c6b6ec98230 100644 --- a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/SecuredHelloHandler.java +++ b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/SecuredHelloHandler.java @@ -47,7 +47,7 @@ public class SecuredHelloHandler // In this example the name can be whatever you like since we are not // dealing with webapp realms. String realmResourceName = "etc/realm.properties"; - Resource realmResource = ResourceFactory.of(server).newClassPathResource("etc/realm.properties"); + Resource realmResource = ResourceFactory.of(server).newClassLoaderResource("etc/realm.properties", false); if (realmResource == null) throw new FileNotFoundException("Unable to find " + realmResourceName); diff --git a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ServerWithAnnotations.java b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ServerWithAnnotations.java index fd4718ebe00..4370c9b157b 100644 --- a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ServerWithAnnotations.java +++ b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-embedded/src/main/java/org/eclipse/jetty/ee10/demos/ServerWithAnnotations.java @@ -71,7 +71,7 @@ public class ServerWithAnnotations // Configure a LoginService String realmResourceName = "etc/realm.properties"; - org.eclipse.jetty.util.resource.Resource realmResource = webapp.getResourceFactory().newClassPathResource(realmResourceName); + org.eclipse.jetty.util.resource.Resource realmResource = webapp.getResourceFactory().newClassLoaderResource(realmResourceName, false); if (realmResource == null) throw new FileNotFoundException("Unable to find " + realmResourceName); diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebXmlConfiguration.java b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebXmlConfiguration.java index d428e320a2a..93d2da6db16 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebXmlConfiguration.java +++ b/jetty-ee10/jetty-ee10-webapp/src/main/java/org/eclipse/jetty/ee10/webapp/WebXmlConfiguration.java @@ -46,7 +46,7 @@ public class WebXmlConfiguration extends AbstractConfiguration String defaultsDescriptor = context.getDefaultsDescriptor(); if (defaultsDescriptor != null && defaultsDescriptor.length() > 0) { - Resource dftResource = context.getResourceFactory().newSystemResource(defaultsDescriptor); + Resource dftResource = context.getResourceFactory().newClassLoaderResource(defaultsDescriptor); if (Resources.missing(dftResource)) { String pkg = WebXmlConfiguration.class.getPackageName().replace(".", "/") + "/"; @@ -80,7 +80,7 @@ public class WebXmlConfiguration extends AbstractConfiguration { if (overrideDescriptor != null && overrideDescriptor.length() > 0) { - Resource orideResource = context.getResourceFactory().newSystemResource(overrideDescriptor); + Resource orideResource = context.getResourceFactory().newClassLoaderResource(overrideDescriptor); if (Resources.missing(orideResource)) orideResource = context.newResource(overrideDescriptor); if (Resources.isReadableFile(orideResource)) diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ExampleServerXml.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ExampleServerXml.java index 025185acde0..4deef77e314 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ExampleServerXml.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ExampleServerXml.java @@ -28,7 +28,7 @@ public class ExampleServerXml // Find Jetty XML (in classpath) that configures and starts Server. // See src/main/resources/exampleserver.xml ResourceFactory.LifeCycle resourceFactory = ResourceFactory.lifecycle(); - Resource serverXml = resourceFactory.newSystemResource("exampleserver.xml"); + Resource serverXml = resourceFactory.newClassLoaderResource("exampleserver.xml"); XmlConfiguration xml = new XmlConfiguration(serverXml); xml.getProperties().put("http.port", Integer.toString(port)); Server server = (Server)xml.configure(); diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/FileServerXml.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/FileServerXml.java index a95715f0022..a46cfdc9f67 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/FileServerXml.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/FileServerXml.java @@ -35,7 +35,7 @@ public class FileServerXml // Find Jetty XML (in classpath) that configures and starts Server. // See src/main/resources/fileserver.xml ResourceFactory.LifeCycle resourceFactory = ResourceFactory.lifecycle(); - Resource fileServerXml = resourceFactory.newSystemResource("fileserver.xml"); + Resource fileServerXml = resourceFactory.newClassLoaderResource("fileserver.xml"); Resource baseResource = resourceFactory.newResource(basePath); XmlConfiguration configuration = new XmlConfiguration(fileServerXml); configuration.getProperties().put("fileserver.baseResource", baseResource.toString()); diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/OneWebAppWithJsp.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/OneWebAppWithJsp.java index d10b9b57552..f71f57bbad0 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/OneWebAppWithJsp.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/OneWebAppWithJsp.java @@ -77,7 +77,7 @@ public class OneWebAppWithJsp // can be started and stopped according to the lifecycle of the server // itself. String realmResourceName = "etc/realm.properties"; - Resource realmResource = webapp.getResourceFactory().newClassPathResource(realmResourceName); + Resource realmResource = webapp.getResourceFactory().newClassLoaderResource(realmResourceName, false); if (realmResource == null) throw new FileNotFoundException("Unable to find " + realmResourceName); diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/SecuredHelloHandler.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/SecuredHelloHandler.java index 9db9af22544..f190d3df793 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/SecuredHelloHandler.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/SecuredHelloHandler.java @@ -47,7 +47,7 @@ public class SecuredHelloHandler // In this example the name can be whatever you like since we are not // dealing with webapp realms. String realmResourceName = "etc/realm.properties"; - Resource realmResource = ResourceFactory.of(server).newClassPathResource("etc/realm.properties"); + Resource realmResource = ResourceFactory.of(server).newClassLoaderResource("etc/realm.properties", false); if (realmResource == null) throw new FileNotFoundException("Unable to find " + realmResourceName); diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ServerWithAnnotations.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ServerWithAnnotations.java index e7815e8204a..24fbe296ee4 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ServerWithAnnotations.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-embedded/src/main/java/org/eclipse/jetty/ee9/demos/ServerWithAnnotations.java @@ -72,7 +72,7 @@ public class ServerWithAnnotations // Configure a LoginService String realmResourceName = "etc/realm.properties"; - org.eclipse.jetty.util.resource.Resource realmResource = webapp.getResourceFactory().newClassPathResource(realmResourceName); + org.eclipse.jetty.util.resource.Resource realmResource = webapp.getResourceFactory().newClassLoaderResource(realmResourceName, false); if (realmResource == null) throw new FileNotFoundException("Unable to find " + realmResourceName); diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebXmlConfiguration.java b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebXmlConfiguration.java index 7a5d142a1a5..2f8a4a0d43c 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebXmlConfiguration.java +++ b/jetty-ee9/jetty-ee9-webapp/src/main/java/org/eclipse/jetty/ee9/webapp/WebXmlConfiguration.java @@ -50,7 +50,7 @@ public class WebXmlConfiguration extends AbstractConfiguration String defaultsDescriptor = context.getDefaultsDescriptor(); if (defaultsDescriptor != null && defaultsDescriptor.length() > 0) { - Resource dftResource = context.getResourceFactory().newSystemResource(defaultsDescriptor); + Resource dftResource = context.getResourceFactory().newClassLoaderResource(defaultsDescriptor); if (Resources.missing(dftResource)) { String pkg = WebXmlConfiguration.class.getPackageName().replace(".", "/") + "/"; @@ -84,7 +84,7 @@ public class WebXmlConfiguration extends AbstractConfiguration { if (overrideDescriptor != null && overrideDescriptor.length() > 0) { - Resource orideResource = context.getResourceFactory().newSystemResource(overrideDescriptor); + Resource orideResource = context.getResourceFactory().newClassLoaderResource(overrideDescriptor); if (orideResource == null) orideResource = context.newResource(overrideDescriptor); context.getMetaData().addOverrideDescriptor(new OverrideDescriptor(orideResource));