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:
parent
0b0d7d3282
commit
6848403d34
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -124,6 +124,6 @@ public class EmptyResource extends Resource
|
|||
@Override
|
||||
public Resource addPath(String path) throws IOException, MalformedURLException
|
||||
{
|
||||
return null;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue