Search in sources :

Example 1 with WebResourceSet

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
                }
            }
        }
    }
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) IOException(java.io.IOException) File(java.io.File)

Example 2 with WebResourceSet

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();
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet)

Example 3 with WebResourceSet

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;
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with WebResourceSet

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;
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) File(java.io.File)

Example 5 with WebResourceSet

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());
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) WebResource(org.apache.catalina.WebResource) File(java.io.File) Test(org.junit.Test)

Aggregations

WebResourceSet (org.apache.catalina.WebResourceSet)22 File (java.io.File)8 IOException (java.io.IOException)3 WebResource (org.apache.catalina.WebResource)3 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 TrackedWebResource (org.apache.catalina.TrackedWebResource)2 WebResourceRoot (org.apache.catalina.WebResourceRoot)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 Host (org.apache.catalina.Host)1 Loader (org.apache.catalina.Loader)1 WebappLoader (org.apache.catalina.loader.WebappLoader)1 DeploymentLoader (org.apache.openejb.config.DeploymentLoader)1 Test (org.junit.Test)1