diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java index 733af0e699b..9cb9b7487b0 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ResourceHandler.java @@ -152,18 +152,9 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory, public Resource getResource(String path) throws IOException { if (LOG.isDebugEnabled()) - LOG.debug("{} newResource({}): baseResource:{}", _context == null ? _baseResource : _context, path, _baseResource); + LOG.debug("{} getResource({}): baseResource:{}", _context == null ? _baseResource : _context, path, _baseResource); - if (path == null) - { - throw new IOException("null path"); - } - else if (!path.startsWith("/")) - { - throw new IOException("Invalid path reference: " + path); - } - - try + if (path != null && path.startsWith("/")) { Resource r = null; @@ -172,15 +163,19 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory, path = URIUtil.canonicalPath(path); r = _baseResource.addPath(path); - if (r != null && r.isAlias() && (_context == null || !_context.checkAlias(path, r))) + if (r.isAlias() && (_context == null || !_context.checkAlias(path, r))) { if (LOG.isDebugEnabled()) - LOG.debug("resource={} alias={}", r, r.getAlias()); - throw new IOException("Unacceptable alias reference: " + r); + LOG.debug("Rejected alias resource={} alias={}", r, r.getAlias()); + throw new IOException("Rejected (see debug logs)"); } } else if (_context != null) + { r = _context.getResource(path); + if (r != null) + return r; + } if ((r == null || !r.exists()) && path.endsWith("/jetty-dir.css")) r = getStylesheet(); @@ -188,10 +183,6 @@ public class ResourceHandler extends HandlerWrapper implements ResourceFactory, if (r != null) return r; } - catch (Exception e) - { - LOG.debug("Unable to get Resource for {}", path, e); - } throw new IOException("Unable to find Resource for " + path); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java index 07831e37b11..ebce0643939 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java @@ -124,6 +124,6 @@ public class EmptyResource extends Resource @Override public Resource addPath(String path) throws IOException, MalformedURLException { - return null; + return this; } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index a15f466802c..0ee6c0f34f9 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -413,7 +413,7 @@ public abstract class Resource implements ResourceFactory, Closeable * given name. * * @param path The path segment to add, which is not encoded - * @return the Resource for the resolved path within this Resource. + * @return the Resource for the resolved path within this Resource, never null * @throws IOException if unable to resolve the path * @throws MalformedURLException if the resolution of the path fails because the input path parameter is malformed. */ diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java index d2159656106..87321e19412 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java @@ -222,7 +222,7 @@ public class ResourceCollection extends Resource if (path == null) { - throw new MalformedURLException(); + throw new MalformedURLException("null path"); } if (path.length() == 0 || URIUtil.SLASH.equals(path)) @@ -270,11 +270,13 @@ public class ResourceCollection extends Resource { return resource; } + if (resources != null) { return new ResourceCollection(resources.toArray(new Resource[0])); } - return null; + + throw new MalformedURLException("path does not result in Resource: " + path); } @Override diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java index 93ab4fa2ffc..58e65bc0f99 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/URLResource.java @@ -290,7 +290,9 @@ public class URLResource extends Resource throws IOException, MalformedURLException { if (path == null) - return null; + { + throw new MalformedURLException("null path"); + } path = URIUtil.canonicalPath(path); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index f9702e8b8ee..efc5d7ce3c9 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -88,7 +88,6 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility */ public interface Context extends ClassVisibilityChecker { - /** * Convert a URL or path to a Resource. * The default implementation