Search in sources :

Example 6 with BaseDirContext

use of org.apache.naming.resources.BaseDirContext in project tomcat70 by apache.

the class StandardContext method resourcesStart.

/**
 * Allocate resources, including proxy.
 * Return <code>true</code> if initialization was successfull,
 * or <code>false</code> otherwise.
 */
public boolean resourcesStart() {
    boolean ok = true;
    Hashtable<String, String> env = new Hashtable<String, String>();
    if (getParent() != null)
        env.put(ProxyDirContext.HOST, getParent().getName());
    env.put(ProxyDirContext.CONTEXT, getName());
    try {
        ProxyDirContext proxyDirContext = new ProxyDirContext(env, webappResources);
        if (webappResources instanceof FileDirContext) {
            filesystemBased = true;
            ((FileDirContext) webappResources).setAllowLinking(isAllowLinking());
        }
        if (webappResources instanceof BaseDirContext) {
            ((BaseDirContext) webappResources).setDocBase(getBasePath());
            ((BaseDirContext) webappResources).setCached(isCachingAllowed());
            ((BaseDirContext) webappResources).setCacheTTL(getCacheTTL());
            ((BaseDirContext) webappResources).setCacheMaxSize(getCacheMaxSize());
            ((BaseDirContext) webappResources).allocate();
            // Alias support
            ((BaseDirContext) webappResources).setAliases(getAliases());
            if (effectiveMajorVersion >= 3 && addWebinfClassesResources) {
                try {
                    DirContext webInfCtx = (DirContext) webappResources.lookup("/WEB-INF/classes");
                    // Do the lookup to make sure it exists
                    webInfCtx.lookup("META-INF/resources");
                    ((BaseDirContext) webappResources).addAltDirContext(webInfCtx);
                } catch (NamingException e) {
                // Doesn't exist - ignore and carry on
                }
            }
        }
        // Register the cache in JMX
        if (isCachingAllowed() && proxyDirContext.getCache() != null) {
            String contextName = getName();
            if (!contextName.startsWith("/")) {
                contextName = "/" + contextName;
            }
            ObjectName resourcesName = new ObjectName(this.getDomain() + ":type=Cache,host=" + getHostname() + ",context=" + contextName);
            Registry.getRegistry(null, null).registerComponent(proxyDirContext.getCache(), resourcesName, null);
        }
        super.setResources(proxyDirContext);
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.error(sm.getString("standardContext.resourcesStart"), t);
        ok = false;
    }
    return (ok);
}
Also used : Hashtable(java.util.Hashtable) FileDirContext(org.apache.naming.resources.FileDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) NamingException(javax.naming.NamingException) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) EmptyDirContext(org.apache.naming.resources.EmptyDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) FileDirContext(org.apache.naming.resources.FileDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) ObjectName(javax.management.ObjectName)

Example 7 with BaseDirContext

use of org.apache.naming.resources.BaseDirContext in project tomcat70 by apache.

the class StandardContext method setResources.

/**
 * Set the resources DirContext object with which this Container is
 * associated.
 *
 * @param resources The newly associated DirContext
 */
@Override
public synchronized void setResources(DirContext resources) {
    if (getState().isAvailable()) {
        throw new IllegalStateException(sm.getString("standardContext.resourcesStart"));
    }
    DirContext oldResources = this.webappResources;
    if (oldResources == resources)
        return;
    if (resources instanceof BaseDirContext) {
        // Caching
        ((BaseDirContext) resources).setCached(isCachingAllowed());
        ((BaseDirContext) resources).setCacheTTL(getCacheTTL());
        ((BaseDirContext) resources).setCacheMaxSize(getCacheMaxSize());
        ((BaseDirContext) resources).setCacheObjectMaxSize(getCacheObjectMaxSize());
        // Alias support
        ((BaseDirContext) resources).setAliases(getAliases());
    }
    if (resources instanceof FileDirContext) {
        filesystemBased = true;
        ((FileDirContext) resources).setAllowLinking(isAllowLinking());
    }
    this.webappResources = resources;
    // The proxied resources will be refreshed on start
    super.setResources(null);
    support.firePropertyChange("resources", oldResources, this.webappResources);
}
Also used : FileDirContext(org.apache.naming.resources.FileDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) EmptyDirContext(org.apache.naming.resources.EmptyDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Example 8 with BaseDirContext

use of org.apache.naming.resources.BaseDirContext in project Payara by payara.

the class StandardContext method setAlternateResources.

private synchronized void setAlternateResources(AlternateDocBase alternateDocBase, DirContext resources) {
    if (started) {
        throw new IllegalStateException(rb.getString(LogFacade.RESOURCES_STARTED));
    }
    final DirContext oldResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
    if (oldResources == resources)
        return;
    if (resources instanceof BaseDirContext) {
        ((BaseDirContext) resources).setCached(isCachingAllowed());
        ((BaseDirContext) resources).setCacheTTL(getCacheTTL());
        ((BaseDirContext) resources).setCacheMaxSize(getCacheMaxSize());
    }
    if (resources instanceof FileDirContext) {
        filesystemBased = true;
        ((FileDirContext) resources).setCaseSensitive(isCaseSensitive());
        ((FileDirContext) resources).setAllowLinking(isAllowLinking());
    }
    alternateDocBase.setWebappResources(ContextsAdapterUtility.wrap(resources));
    // The proxied resources will be refreshed on start
    alternateDocBase.setResources(null);
}
Also used : FileDirContext(org.apache.naming.resources.FileDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Aggregations

BaseDirContext (org.apache.naming.resources.BaseDirContext)8 ProxyDirContext (org.apache.naming.resources.ProxyDirContext)8 DirContext (javax.naming.directory.DirContext)7 FileDirContext (org.apache.naming.resources.FileDirContext)7 WARDirContext (org.apache.naming.resources.WARDirContext)7 WebDirContext (org.apache.naming.resources.WebDirContext)4 Hashtable (java.util.Hashtable)3 EmptyDirContext (org.apache.naming.resources.EmptyDirContext)3 ObjectName (javax.management.ObjectName)2 Lifecycle (org.apache.catalina.Lifecycle)2 AlternateDocBase (org.glassfish.grizzly.http.server.util.AlternateDocBase)2 NamingException (javax.naming.NamingException)1 LifecycleException (org.apache.catalina.LifecycleException)1