Search in sources :

Example 1 with WebResourceRoot

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

the class StandardContextSF method storeChildren.

/**
     * Store the specified context element children.
     *
     * @param aWriter Current output writer
     * @param indent Indentation level
     * @param aContext Context to store
     * @param parentDesc The element description
     * @throws Exception Configuration storing error
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext, StoreDescription parentDesc) throws Exception {
    if (aContext instanceof StandardContext) {
        StandardContext context = (StandardContext) aContext;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = context.findLifecycleListeners();
        ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
        for (LifecycleListener listener : listeners) {
            if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
                listenersArray.add(listener);
            }
        }
        storeElementArray(aWriter, indent, listenersArray.toArray());
        // Store nested <Valve> elements
        Valve[] valves = context.getPipeline().getValves();
        storeElementArray(aWriter, indent, valves);
        // Store nested <Loader> elements
        Loader loader = context.getLoader();
        storeElement(aWriter, indent, loader);
        // Store nested <Manager> elements
        if (context.getCluster() == null || !context.getDistributable()) {
            Manager manager = context.getManager();
            storeElement(aWriter, indent, manager);
        }
        // Store nested <Realm> element
        Realm realm = context.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            // @TODO is this case possible?
            if (context.getParent() != null) {
                parentRealm = context.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested resources
        WebResourceRoot resources = context.getResources();
        storeElement(aWriter, indent, resources);
        // Store nested <WrapperListener> elements
        String[] wLifecycles = context.findWrapperLifecycles();
        getStoreAppender().printTagArray(aWriter, "WrapperListener", indent + 2, wLifecycles);
        // Store nested <WrapperLifecycle> elements
        String[] wListeners = context.findWrapperListeners();
        getStoreAppender().printTagArray(aWriter, "WrapperLifecycle", indent + 2, wListeners);
        // Store nested <Parameter> elements
        ApplicationParameter[] appParams = context.findApplicationParameters();
        storeElementArray(aWriter, indent, appParams);
        // Store nested naming resources elements (EJB,Resource,...)
        NamingResourcesImpl nresources = context.getNamingResources();
        storeElement(aWriter, indent, nresources);
        // Store nested watched resources <WatchedResource>
        String[] wresources = context.findWatchedResources();
        wresources = filterWatchedResources(context, wresources);
        getStoreAppender().printTagArray(aWriter, "WatchedResource", indent + 2, wresources);
        // Store nested <JarScanner> elements
        JarScanner jarScanner = context.getJarScanner();
        storeElement(aWriter, indent, jarScanner);
        // Store nested <CookieProcessor> elements
        CookieProcessor cookieProcessor = context.getCookieProcessor();
        storeElement(aWriter, indent, cookieProcessor);
    }
}
Also used : ApplicationParameter(org.apache.tomcat.util.descriptor.web.ApplicationParameter) ArrayList(java.util.ArrayList) Loader(org.apache.catalina.Loader) LifecycleListener(org.apache.catalina.LifecycleListener) Manager(org.apache.catalina.Manager) JarScanner(org.apache.tomcat.JarScanner) ThreadLocalLeakPreventionListener(org.apache.catalina.core.ThreadLocalLeakPreventionListener) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) StandardContext(org.apache.catalina.core.StandardContext) Valve(org.apache.catalina.Valve) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) Realm(org.apache.catalina.Realm) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 2 with WebResourceRoot

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

the class FileResourceSet method getResource.

@Override
public WebResource getResource(String path) {
    checkPath(path);
    String webAppMount = getWebAppMount();
    WebResourceRoot root = getRoot();
    if (path.equals(webAppMount)) {
        File f = file("", true);
        if (f == null) {
            return new EmptyResource(root, path);
        }
        return new FileResource(root, path, f, isReadOnly(), null);
    }
    if (path.charAt(path.length() - 1) != '/') {
        path = path + '/';
    }
    if (webAppMount.startsWith(path)) {
        String name = path.substring(0, path.length() - 1);
        name = name.substring(name.lastIndexOf('/') + 1);
        if (name.length() > 0) {
            return new VirtualResource(root, path, name);
        }
    }
    return new EmptyResource(root, path);
}
Also used : File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 3 with WebResourceRoot

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

the class ApplicationContext method getResourceAsStream.

@Override
public InputStream getResourceAsStream(String path) {
    String validatedPath = validateResourcePath(path, false);
    if (validatedPath == null) {
        return null;
    }
    WebResourceRoot resources = context.getResources();
    if (resources != null) {
        return resources.getResource(validatedPath).getInputStream();
    }
    return null;
}
Also used : WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 4 with WebResourceRoot

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

the class StandardContext method backgroundProcess.

@Override
public void backgroundProcess() {
    if (!getState().isAvailable())
        return;
    Loader loader = getLoader();
    if (loader != null) {
        try {
            loader.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.loader", loader), e);
        }
    }
    Manager manager = getManager();
    if (manager != null) {
        try {
            manager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.manager", manager), e);
        }
    }
    WebResourceRoot resources = getResources();
    if (resources != null) {
        try {
            resources.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.resources", resources), e);
        }
    }
    InstanceManager instanceManager = getInstanceManager();
    if (instanceManager != null) {
        try {
            instanceManager.backgroundProcess();
        } catch (Exception e) {
            log.warn(sm.getString("standardContext.backgroundProcess.instanceManager", resources), e);
        }
    }
    super.backgroundProcess();
}
Also used : InstanceManager(org.apache.tomcat.InstanceManager) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) StandardManager(org.apache.catalina.session.StandardManager) LifecycleException(org.apache.catalina.LifecycleException) ListenerNotFoundException(javax.management.ListenerNotFoundException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) MalformedURLException(java.net.MalformedURLException) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 5 with WebResourceRoot

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

the class AbstractArchiveResourceSet method getResource.

@Override
public final WebResource getResource(String path) {
    checkPath(path);
    String webAppMount = getWebAppMount();
    WebResourceRoot root = getRoot();
    if (path.startsWith(webAppMount)) {
        String pathInJar = getInternalPath() + path.substring(webAppMount.length(), path.length());
        // Always strip off the leading '/' to get the JAR path
        if (pathInJar.length() > 0 && pathInJar.charAt(0) == '/') {
            pathInJar = pathInJar.substring(1);
        }
        if (pathInJar.equals("")) {
            // This is a directory resource so the path must end with /
            if (!path.endsWith("/")) {
                path = path + "/";
            }
            return new JarResourceRoot(root, new File(getBase()), baseUrlString, path);
        } else {
            Map<String, JarEntry> jarEntries = getArchiveEntries(true);
            JarEntry jarEntry = null;
            if (!(pathInJar.charAt(pathInJar.length() - 1) == '/')) {
                if (jarEntries == null) {
                    jarEntry = getArchiveEntry(pathInJar + '/');
                } else {
                    jarEntry = jarEntries.get(pathInJar + '/');
                }
                if (jarEntry != null) {
                    path = path + '/';
                }
            }
            if (jarEntry == null) {
                if (jarEntries == null) {
                    jarEntry = getArchiveEntry(pathInJar);
                } else {
                    jarEntry = jarEntries.get(pathInJar);
                }
            }
            if (jarEntry == null) {
                return new EmptyResource(root, path);
            } else {
                return createArchiveResource(jarEntry, path, getManifest());
            }
        }
    } else {
        return new EmptyResource(root, path);
    }
}
Also used : JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File) 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