Issue #5133 - Reworking WebAppContext.extraClasspath

+ Reverting name ResourceFactory.newResource(String)
  to .getResource(String)
+ Reintroducing Resource.getResource(String)
+ ResourceHandler.getResource(String) cleaned up
  in light of Exception handling requirement
+ Resource.addPath(String) implementations can
  never return null now

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2020-08-12 13:06:09 -05:00
parent 0b0d7d3282
commit 6848403d34
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
6 changed files with 18 additions and 24 deletions

View File

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

View File

@ -124,6 +124,6 @@ public class EmptyResource extends Resource
@Override
public Resource addPath(String path) throws IOException, MalformedURLException
{
return null;
return this;
}
}

View File

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

View File

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

View File

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

View File

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