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);
}
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;
}
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);
}
}
}
}
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);
}
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);
}
Aggregations