use of org.apache.catalina.WebResourceSet in project tomee by apache.
the class TomEEWebappClassLoader method setResources.
@Override
public void setResources(final WebResourceRoot resources) {
this.resources = resources;
if (StandardRoot.class.isInstance(resources)) {
final List<WebResourceSet> jars = (List<WebResourceSet>) Reflections.get(resources, "jarResources");
if (jars != null && !jars.isEmpty()) {
final Iterator<WebResourceSet> jarIt = jars.iterator();
while (jarIt.hasNext()) {
final WebResourceSet set = jarIt.next();
if (set.getBaseUrl() == null) {
continue;
}
final File file = URLs.toFile(set.getBaseUrl());
try {
if (file.exists() && (!TomEEClassLoaderEnricher.validateJarFile(file) || !jarIsAccepted(file))) {
// need to remove this resource
LOGGER.warning("Removing " + file.getAbsolutePath() + " since it is offending");
jarIt.remove();
}
} catch (final IOException e) {
// ignore
}
}
}
}
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method destroyInternal.
@Override
protected void destroyInternal() throws LifecycleException {
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
webResourceSet.destroy();
}
}
unregister(cacheJmxName);
super.destroyInternal();
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class StandardRoot method listWebAppPaths.
@Override
public Set<String> listWebAppPaths(String path) {
path = validate(path);
// Set because we don't want duplicates
Set<String> result = new HashSet<>();
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
if (!webResourceSet.getClassLoaderOnly()) {
result.addAll(webResourceSet.listWebAppPaths(path));
}
}
}
if (result.size() == 0) {
return null;
}
return result;
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class TestJarResourceSetInternal method getWebResourceRoot.
@Override
public WebResourceRoot getWebResourceRoot() {
File f = new File("test/webresources/dir1-internal.jar");
TesterWebResourceRoot root = new TesterWebResourceRoot();
WebResourceSet webResourceSet = new JarResourceSet(root, "/", f.getAbsolutePath(), "/dir1");
root.setMainResources(webResourceSet);
return root;
}
use of org.apache.catalina.WebResourceSet in project tomcat by apache.
the class TestResourceJars method testNonStaticResources.
@Test
public void testNonStaticResources() {
File empty = new File("test/webresources/dir3");
File jar = new File("test/webresources/non-static-resources.jar");
TesterWebResourceRoot root = new TesterWebResourceRoot();
// Use empty dir for root of web app.
WebResourceSet webResourceSet = new DirResourceSet(root, "/", empty.getAbsolutePath(), "/");
root.setMainResources(webResourceSet);
// If this JAR was in a web application, this is equivalent to how it
// would be added
JarResourceSet test = new JarResourceSet(root, "/", jar.getAbsolutePath(), "/META-INF/resources");
test.setStaticOnly(true);
root.addJarResources(test);
WebResource resource = root.getClassLoaderResource("/org/apache/tomcat/unittest/foo.txt");
Assert.assertFalse(resource.exists());
}
Aggregations