Skip to content

Commit

Permalink
Issue #5133 - Reworking WebAppContext.extraClasspath
Browse files Browse the repository at this point in the history
+ 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 <[email protected]>
  • Loading branch information
joakime committed Aug 12, 2020
1 parent 0b0d7d3 commit 6848403
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,9 @@ public MimeTypes getMimeTypes()
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;

Expand All @@ -172,26 +163,26 @@ else if (!path.startsWith("/"))
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();

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ public String[] list()
@Override
public Resource addPath(String path) throws IOException, MalformedURLException
{
return null;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public abstract boolean renameTo(Resource dest)
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public Resource addPath(String path) throws IOException

if (path == null)
{
throw new MalformedURLException();
throw new MalformedURLException("null path");
}

if (path.length() == 0 || URIUtil.SLASH.equals(path))
Expand Down Expand Up @@ -270,11 +270,13 @@ public Resource addPath(String path) throws IOException
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ public Resource addPath(String path)
throws IOException, MalformedURLException
{
if (path == null)
return null;
{
throw new MalformedURLException("null path");
}

path = URIUtil.canonicalPath(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6848403

Please sign in to comment.