Search in sources :

Example 11 with WebResourceRoot

use of org.apache.catalina.WebResourceRoot 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;
        }
    }
}
Also used : WebResource(org.apache.catalina.WebResource) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 12 with WebResourceRoot

use of org.apache.catalina.WebResourceRoot in project tomcat by apache.

the class DirResourceSet method getResource.

@Override
public WebResource getResource(String path) {
    checkPath(path);
    String webAppMount = getWebAppMount();
    WebResourceRoot root = getRoot();
    if (path.startsWith(webAppMount)) {
        File f = file(path.substring(webAppMount.length()), false);
        if (f == null) {
            return new EmptyResource(root, path);
        }
        if (!f.exists()) {
            return new EmptyResource(root, path, f);
        }
        if (f.isDirectory() && path.charAt(path.length() - 1) != '/') {
            path = path + '/';
        }
        return new FileResource(root, path, f, isReadOnly(), getManifest());
    } else {
        return new EmptyResource(root, path);
    }
}
Also used : File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 13 with WebResourceRoot

use of org.apache.catalina.WebResourceRoot in project Synthese_2BIN by TheYoungSensei.

the class Main method main.

public static void main(String[] args) throws Exception {
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File("./web").getAbsolutePath());
    WebResourceRoot resources = new StandardRoot(ctx);
    ctx.setResources(resources);
    tomcat.start();
    tomcat.getServer().await();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) StandardContext(org.apache.catalina.core.StandardContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 14 with WebResourceRoot

use of org.apache.catalina.WebResourceRoot in project tomee by apache.

the class TomcatWebAppBuilder method configuredClasspath.

private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
    Loader loader = standardContext.getLoader();
    if (loader != null && LazyStopLoader.class.isInstance(loader)) {
        loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
    }
    if (loader != null) {
        final ClassLoader cl = standardContext.getLoader().getClassLoader();
        if (cl == null) {
            return null;
        }
        final Collection<String> cp = new LinkedList<>();
        final WebResourceRoot webResources = standardContext.getResources();
        if (webResources != null) {
            // to enhance
            for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
                for (final WebResourceSet wr : sets) {
                    final URL base = wr.getBaseUrl();
                    if (base != null) {
                        final File baseFile = URLs.toFile(base);
                        if (baseFile.isDirectory()) {
                            final String[] libs = wr.list("/WEB-INF/lib/");
                            if (libs != null) {
                                for (final String resource : libs) {
                                    cp.add(new File(baseFile, resource).getAbsolutePath());
                                }
                            }
                            final WebResource classes = wr.getResource("/WEB-INF/classes/");
                            if (classes != null) {
                                final String path = classes.getCanonicalPath();
                                if (path != null) {
                                    cp.add(path);
                                }
                            }
                        } else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
                            try {
                                cp.add(baseFile.getCanonicalPath());
                            } catch (final IOException e) {
                                throw new IllegalStateException(e);
                            }
                        }
                    }
                }
            }
        }
        if (!cp.isEmpty()) {
            return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null);
        }
    }
    return null;
}
Also used : WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) DeploymentLoader(org.apache.openejb.config.DeploymentLoader) WebResource(org.apache.catalina.WebResource) IOException(java.io.IOException) LinkedList(java.util.LinkedList) URL(java.net.URL) WebResourceSet(org.apache.catalina.WebResourceSet) File(java.io.File) JarFile(java.util.jar.JarFile) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 15 with WebResourceRoot

use of org.apache.catalina.WebResourceRoot in project tomee by apache.

the class TomcatWebAppBuilder method addConfiguredDocBases.

private void addConfiguredDocBases(final StandardContext standardContext, final ContextInfo contextInfo) {
    if (contextInfo.appInfo.path != null) {
        // add external web resources
        final String contextPath = standardContext.getServletContext().getContextPath();
        final String name = contextPath.isEmpty() ? "ROOT" : contextPath.substring(1);
        final String webResources = SystemInstance.get().getProperty("tomee." + name + ".docBases", contextInfo.appInfo.properties.getProperty("docBases"));
        if (webResources != null) {
            for (final String alt : webResources.trim().split(",")) {
                final String trim = alt.trim();
                if (trim.isEmpty()) {
                    continue;
                }
                if (!new File(trim).isDirectory()) {
                    logger.warning("Can't add docBase which are not directory: " + trim);
                    continue;
                }
                final WebResourceRoot root = standardContext.getResources();
                root.addPreResources(new DirResourceSet(root, "/", trim, "/"));
            }
        }
    }
}
Also used : DirResourceSet(org.apache.catalina.webresources.DirResourceSet) File(java.io.File) JarFile(java.util.jar.JarFile) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Aggregations

WebResourceRoot (org.apache.catalina.WebResourceRoot)15 File (java.io.File)6 Loader (org.apache.catalina.Loader)4 JarFile (java.util.jar.JarFile)3 WebappLoader (org.apache.catalina.loader.WebappLoader)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 LifecycleException (org.apache.catalina.LifecycleException)2 Manager (org.apache.catalina.Manager)2 WebResource (org.apache.catalina.WebResource)2 WebResourceSet (org.apache.catalina.WebResourceSet)2 StandardContext (org.apache.catalina.core.StandardContext)2 DeploymentLoader (org.apache.openejb.config.DeploymentLoader)2 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 JarEntry (java.util.jar.JarEntry)1