Issue #10328 - Review ResourceFactory.newSystemResource (#10533)

* Issue #10328 - Review ResourceFactory.newSystemResource

+ Create a new ResourceFactory.newClassLoaderResource(String, boolean)
+ Make .newSystemResource(String) use it
+ Make .newClassPathResource(String) use it
+ Deprecate .newSystemResource(String)
+ Deprecate .newClassPathResource(String)
+ Adjust own codebase to not use deprecated methods
This commit is contained in:
Joakim Erdfelt 2023-09-20 14:43:22 -07:00 committed by GitHub
parent 3dd030ae61
commit aefa331aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 202 additions and 164 deletions

View File

@ -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;
/**
* <p>ResourceFactory is the source of new {@link Resource} instances.</p>
@ -113,6 +116,8 @@ import org.eclipse.jetty.util.component.Dumpable;
*/
public interface ResourceFactory
{
static final Logger LOG = LoggerFactory.getLogger(ResourceFactory.class);
/**
* <p>Make a directory Resource containing a collection of other directory {@link Resource}s</p>
* @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);
/**
* <p>Construct a system resource from a string.</p>
*
* <p>
* The resource is first attempted to be accessed via the {@link Thread#getContextClassLoader()}
* before being treated as a normal resource.
* </p>
* <p>Construct a Resource from a string reference into classloaders.</p>
*
* @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);
}
/**
* <p>Construct a Resource from a search of ClassLoaders.</p>
*
* <p>
* Search order is:
* </p>
* <ol>
* <li>{@link ClassLoader#getResource(String) java.lang.Thread.currentThread().getContextClassLoader().getResource(String)}</li>
* <li>{@link ClassLoader#getResource(String) ResourceFactory.class.getClassLoader().getResource(String)}</li>
* <li>(optional) {@link ClassLoader#getSystemResource(String) java.lang.ClassLoader.getSystemResource(String)}</li>
* </ol>
*
* <p>
* See {@link ClassLoader#getResource(String)} for rules on resource name parameter.
* </p>
*
* <p>
* 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}).
* </p>
*
* @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<Function<String, URL>> loaders = new ArrayList();
loaders.add(Thread.currentThread().getContextClassLoader()::getResource);
loaders.add(ResourceFactory.class.getClassLoader()::getResource);
if (searchSystemClassLoader)
loaders.add(ClassLoader::getSystemResource);
for (Function<String, URL> 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
}
/**
* <p>Find a classpath resource.</p>
* <p>Construct a Resource from a search of ClassLoaders.</p>
*
* <p>
* 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)}
* </p>
*
* @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);
}
/**
* <p>Construct a Resource from a search of ClassLoaders.</p>
*
* <p>
* Convenience method {@code .newClassLoaderResource(resource, false)}
* </p>
*
* @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)
{

View File

@ -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<String> badReferenceNamesSource()
{
List<String> 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()
{

View File

@ -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.");
}
}

View File

@ -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.

View File

@ -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();

View File

@ -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();

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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))

View File

@ -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();

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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));