use of org.apache.catalina.WebResource in project tomcat by apache.
the class ResolverImpl method resolveResource.
@Override
public boolean resolveResource(int type, String name) {
WebResourceRoot resources = request.getContext().getResources();
WebResource resource = resources.getResource(name);
if (!resource.exists()) {
return false;
} else {
switch(type) {
case 0:
return resource.isDirectory();
case 1:
return resource.isFile();
case 2:
return resource.isFile() && resource.getContentLength() > 0;
default:
return false;
}
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class ExtractingRoot method processWebInfLib.
@Override
protected void processWebInfLib() throws LifecycleException {
// packed WAR file.
if (!super.isPackedWarFile()) {
super.processWebInfLib();
return;
}
File expansionTarget = getExpansionTarget();
if (!expansionTarget.isDirectory()) {
if (!expansionTarget.mkdirs()) {
throw new LifecycleException(sm.getString("extractingRoot.targetFailed", expansionTarget));
}
}
WebResource[] possibleJars = listResources("/WEB-INF/lib", false);
for (WebResource possibleJar : possibleJars) {
if (possibleJar.isFile() && possibleJar.getName().endsWith(".jar")) {
try {
File dest = new File(expansionTarget, possibleJar.getName());
dest = dest.getCanonicalFile();
try (InputStream sourceStream = possibleJar.getInputStream();
OutputStream destStream = new FileOutputStream(dest)) {
IOTools.flow(sourceStream, destStream);
}
createWebResourceSet(ResourceSetType.CLASSES_JAR, "/WEB-INF/classes", dest.toURI().toURL(), "/");
} catch (IOException ioe) {
throw new LifecycleException(sm.getString("extractingRoot.jarFailed", possibleJar.getName()), ioe);
}
}
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class StandardRoot method getResourceInternal.
protected final WebResource getResourceInternal(String path, boolean useClassLoaderResources) {
WebResource result = null;
WebResource virtual = null;
WebResource mainEmpty = null;
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
if (!useClassLoaderResources && !webResourceSet.getClassLoaderOnly() || useClassLoaderResources && !webResourceSet.getStaticOnly()) {
result = webResourceSet.getResource(path);
if (result.exists()) {
return result;
}
if (virtual == null) {
if (result.isVirtual()) {
virtual = result;
} else if (main.equals(webResourceSet)) {
mainEmpty = result;
}
}
}
}
}
// Use the first virtual result if no real result was found
if (virtual != null) {
return virtual;
}
// Default is empty resource in main resources
return mainEmpty;
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetCanonicalPathExists.
// ------------------------------------------------------ getCanonicalPath()
@Test
public final void testGetCanonicalPathExists() {
WebResource exists = resourceRoot.getResource(getMount() + "/d1/d1-f1.txt");
String existsCanonicalPath = exists.getCanonicalPath();
URL existsUrl = exists.getURL();
if ("file".equals(existsUrl.getProtocol())) {
// Should have a canonical path
Assert.assertNotNull(existsCanonicalPath);
} else {
Assert.assertNull(existsCanonicalPath);
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetResourceTraversal.
@Test
public final void testGetResourceTraversal() {
WebResource webResource = null;
try {
webResource = resourceRoot.getResource(getMount() + "/../");
} catch (IllegalArgumentException iae) {
// Expected if mount point is zero length
Assert.assertTrue(getMount().length() == 0);
return;
}
Assert.assertFalse(webResource.exists());
}
Aggregations