Search in sources :

Example 16 with WebResourceSet

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

the class StandardRoot method createMainResourceSet.

protected WebResourceSet createMainResourceSet() {
    String docBase = context.getDocBase();
    WebResourceSet mainResourceSet;
    if (docBase == null) {
        mainResourceSet = new EmptyResourceSet(this);
    } else {
        File f = new File(docBase);
        if (!f.isAbsolute()) {
            f = new File(((Host) context.getParent()).getAppBaseFile(), f.getPath());
        }
        if (f.isDirectory()) {
            mainResourceSet = new DirResourceSet(this, "/", f.getAbsolutePath(), "/");
        } else if (f.isFile() && docBase.endsWith(".war")) {
            mainResourceSet = new WarResourceSet(this, "/", f.getAbsolutePath());
        } else {
            throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", f.getAbsolutePath()));
        }
    }
    return mainResourceSet;
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) Host(org.apache.catalina.Host) File(java.io.File)

Example 17 with WebResourceSet

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

Example 18 with WebResourceSet

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

the class StandardRoot method stopInternal.

@Override
protected void stopInternal() throws LifecycleException {
    for (List<WebResourceSet> list : allResources) {
        for (WebResourceSet webResourceSet : list) {
            webResourceSet.stop();
        }
    }
    if (main != null) {
        main.destroy();
    }
    mainResources.clear();
    for (WebResourceSet webResourceSet : jarResources) {
        webResourceSet.destroy();
    }
    jarResources.clear();
    for (WebResourceSet webResourceSet : classResources) {
        webResourceSet.destroy();
    }
    classResources.clear();
    for (TrackedWebResource trackedResource : trackedResources) {
        log.error(sm.getString("standardRoot.lockedFile", context.getName(), trackedResource.getName()), trackedResource.getCreatedBy());
        try {
            trackedResource.close();
        } catch (IOException e) {
        // Ignore
        }
    }
    cache.clear();
    setState(LifecycleState.STOPPING);
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) IOException(java.io.IOException) TrackedWebResource(org.apache.catalina.TrackedWebResource)

Example 19 with WebResourceSet

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

the class StandardRoot method createWebResourceSet.

@Override
public void createWebResourceSet(ResourceSetType type, String webAppMount, String base, String archivePath, String internalPath) {
    List<WebResourceSet> resourceList;
    WebResourceSet resourceSet;
    switch(type) {
        case PRE:
            resourceList = preResources;
            break;
        case CLASSES_JAR:
            resourceList = classResources;
            break;
        case RESOURCE_JAR:
            resourceList = jarResources;
            break;
        case POST:
            resourceList = postResources;
            break;
        default:
            throw new IllegalArgumentException(sm.getString("standardRoot.createUnknownType", type));
    }
    // This implementation assumes that the base for all resources will be a
    // file.
    File file = new File(base);
    if (file.isFile()) {
        if (archivePath != null) {
            // Must be a JAR nested inside a WAR if archivePath is non-null
            resourceSet = new JarWarResourceSet(this, webAppMount, base, archivePath, internalPath);
        } else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
            resourceSet = new JarResourceSet(this, webAppMount, base, internalPath);
        } else {
            resourceSet = new FileResourceSet(this, webAppMount, base, internalPath);
        }
    } else if (file.isDirectory()) {
        resourceSet = new DirResourceSet(this, webAppMount, base, internalPath);
    } else {
        throw new IllegalArgumentException(sm.getString("standardRoot.createInvalidFile", file));
    }
    if (type.equals(ResourceSetType.CLASSES_JAR)) {
        resourceSet.setClassLoaderOnly(true);
    } else if (type.equals(ResourceSetType.RESOURCE_JAR)) {
        resourceSet.setStaticOnly(true);
    }
    resourceList.add(resourceSet);
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet) File(java.io.File)

Example 20 with WebResourceSet

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

the class StandardRoot method initInternal.

// --------------------------------------------------------------- Lifecycle
@Override
protected void initInternal() throws LifecycleException {
    super.initInternal();
    cacheJmxName = register(cache, getObjectNameKeyProperties() + ",name=Cache");
    registerURLStreamHandlerFactory();
    if (context == null) {
        throw new IllegalStateException(sm.getString("standardRoot.noContext"));
    }
    for (List<WebResourceSet> list : allResources) {
        for (WebResourceSet webResourceSet : list) {
            webResourceSet.init();
        }
    }
}
Also used : WebResourceSet(org.apache.catalina.WebResourceSet)

Aggregations

WebResourceSet (org.apache.catalina.WebResourceSet)21 File (java.io.File)8 IOException (java.io.IOException)3 WebResource (org.apache.catalina.WebResource)3 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 LinkedHashSet (java.util.LinkedHashSet)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