Search in sources :

Example 1 with BaseDirContext

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

the class StandardContext method alternateResourcesStop.

/**
 * Stops this context's alternate doc base resources.
 */
public boolean alternateResourcesStop() {
    boolean ok = true;
    if (alternateDocBases == null || alternateDocBases.isEmpty()) {
        return ok;
    }
    for (AlternateDocBase alternateDocBase : alternateDocBases) {
        final DirContext alternateResources = ContextsAdapterUtility.unwrap(alternateDocBase.getResources());
        if (alternateResources instanceof Lifecycle) {
            try {
                ((Lifecycle) alternateResources).stop();
            } catch (Throwable t) {
                log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
                ok = false;
            }
        }
        final DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
        if (alternateWebappResources instanceof BaseDirContext) {
            try {
                ((BaseDirContext) alternateWebappResources).release();
            } catch (Throwable t) {
                log.log(Level.SEVERE, LogFacade.STOPPING_RESOURCES_EXCEPTION, t);
                ok = false;
            }
        }
    }
    this.alternateDocBases = null;
    return (ok);
}
Also used : AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) Lifecycle(org.apache.catalina.Lifecycle) 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)

Example 2 with BaseDirContext

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

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 BaseDirContext) {
            ((BaseDirContext) webappResources).setDocBase(getBasePath(getDocBase()));
            ((BaseDirContext) webappResources).allocate();
        }
        this.resources = proxyDirContext;
    } catch (Throwable t) {
        if (log.isLoggable(Level.FINE)) {
            String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCES_EXCEPTION), getName());
            log.log(Level.SEVERE, msg, t);
        } else {
            log.log(Level.SEVERE, LogFacade.STARTING_RESOURCE_EXCEPTION_MESSAGE, new Object[] { getName(), t.getMessage() });
        }
        ok = false;
    }
    return ok;
}
Also used : Hashtable(java.util.Hashtable) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext)

Example 3 with BaseDirContext

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

the class StandardContext method alternateResourcesStart.

/**
 * Starts this context's alternate doc base resources.
 */
public void alternateResourcesStart() throws LifecycleException {
    if (alternateDocBases == null || alternateDocBases.isEmpty()) {
        return;
    }
    Hashtable<String, String> env = new Hashtable<String, String>();
    if (getParent() != null) {
        env.put(ProxyDirContext.HOST, getParent().getName());
    }
    env.put(ProxyDirContext.CONTEXT, getName());
    for (AlternateDocBase alternateDocBase : alternateDocBases) {
        String basePath = alternateDocBase.getBasePath();
        DirContext alternateWebappResources = ContextsAdapterUtility.unwrap(alternateDocBase.getWebappResources());
        try {
            ProxyDirContext proxyDirContext = new ProxyDirContext(env, alternateWebappResources);
            if (alternateWebappResources instanceof BaseDirContext) {
                ((BaseDirContext) alternateWebappResources).setDocBase(basePath);
                ((BaseDirContext) alternateWebappResources).allocate();
            }
            alternateDocBase.setResources(ContextsAdapterUtility.wrap(proxyDirContext));
        } catch (Throwable t) {
            if (log.isLoggable(Level.FINE)) {
                String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCES_EXCEPTION), getName());
                throw new LifecycleException(msg, t);
            } else {
                String msg = MessageFormat.format(rb.getString(LogFacade.STARTING_RESOURCE_EXCEPTION_MESSAGE), new Object[] { getName(), t.getMessage() });
                throw new LifecycleException(msg);
            }
        }
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) Hashtable(java.util.Hashtable) 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) ProxyDirContext(org.apache.naming.resources.ProxyDirContext)

Example 4 with BaseDirContext

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

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 (started) {
        throw new IllegalStateException(rb.getString(LogFacade.RESOURCES_STARTED));
    }
    DirContext oldResources = this.webappResources;
    if (oldResources == resources)
        return;
    if (resources instanceof BaseDirContext) {
        BaseDirContext baseDirContext = (BaseDirContext) resources;
        baseDirContext.setCached(isCachingAllowed());
        baseDirContext.setCacheTTL(getCacheTTL());
        baseDirContext.setCacheMaxSize(getCacheMaxSize());
    }
    if (resources instanceof FileDirContext) {
        filesystemBased = true;
        FileDirContext fileDirContext = (FileDirContext) resources;
        fileDirContext.setCaseSensitive(isCaseSensitive());
        fileDirContext.setAllowLinking(isAllowLinking());
    }
    this.webappResources = resources;
    // The proxied resources will be refreshed on start
    this.resources = 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) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext)

Example 5 with BaseDirContext

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

the class StandardContext method resourcesStop.

/**
 * Deallocate resources and destroy proxy.
 */
public boolean resourcesStop() {
    boolean ok = true;
    DirContext resources = getResourcesInternal();
    try {
        if (resources != null) {
            if (resources instanceof Lifecycle) {
                ((Lifecycle) resources).stop();
            }
            if (webappResources instanceof BaseDirContext) {
                ((BaseDirContext) webappResources).release();
            }
            // Unregister the cache in JMX
            if (isCachingAllowed()) {
                String contextName = getName();
                if (!contextName.startsWith("/")) {
                    contextName = "/" + contextName;
                }
                ObjectName resourcesName = new ObjectName(this.getDomain() + ":type=Cache,host=" + getHostname() + ",context=" + contextName);
                Registry.getRegistry(null, null).unregisterComponent(resourcesName);
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.error(sm.getString("standardContext.resourcesStop"), t);
        ok = false;
    }
    super.setResources(null);
    return (ok);
}
Also used : Lifecycle(org.apache.catalina.Lifecycle) 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) ObjectName(javax.management.ObjectName)

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