use of org.apache.catalina.Loader in project tomcat by apache.
the class StandardContext method bind.
@Override
public ClassLoader bind(boolean usePrivilegedAction, ClassLoader originalClassLoader) {
Loader loader = getLoader();
ClassLoader webApplicationClassLoader = null;
if (loader != null) {
webApplicationClassLoader = loader.getClassLoader();
}
if (originalClassLoader == null) {
if (usePrivilegedAction) {
PrivilegedAction<ClassLoader> pa = new PrivilegedGetTccl();
originalClassLoader = AccessController.doPrivileged(pa);
} else {
originalClassLoader = Thread.currentThread().getContextClassLoader();
}
}
if (webApplicationClassLoader == null || webApplicationClassLoader == originalClassLoader) {
// null to indicate this.
return null;
}
ThreadBindingListener threadBindingListener = getThreadBindingListener();
if (usePrivilegedAction) {
PrivilegedAction<Void> pa = new PrivilegedSetTccl(webApplicationClassLoader);
AccessController.doPrivileged(pa);
} else {
Thread.currentThread().setContextClassLoader(webApplicationClassLoader);
}
if (threadBindingListener != null) {
try {
threadBindingListener.bind();
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log.error(sm.getString("standardContext.threadBindingListenerError", getName()), t);
}
}
return originalClassLoader;
}
use of org.apache.catalina.Loader in project tomcat by apache.
the class ClusterManagerBase method getClassLoaders.
public static ClassLoader[] getClassLoaders(Context context) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Loader loader = context.getLoader();
ClassLoader classLoader = null;
if (loader != null) {
classLoader = loader.getClassLoader();
}
if (classLoader == null) {
classLoader = tccl;
}
if (classLoader == tccl) {
return new ClassLoader[] { classLoader };
} else {
return new ClassLoader[] { classLoader, tccl };
}
}
use of org.apache.catalina.Loader in project tomcat by apache.
the class ReplicatedContext method getClassLoaders.
public ClassLoader[] getClassLoaders() {
Loader loader = null;
ClassLoader classLoader = null;
loader = this.getLoader();
if (loader != null)
classLoader = loader.getClassLoader();
if (classLoader == null)
classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == Thread.currentThread().getContextClassLoader()) {
return new ClassLoader[] { classLoader };
} else {
return new ClassLoader[] { classLoader, Thread.currentThread().getContextClassLoader() };
}
}
use of org.apache.catalina.Loader in project tomcat by apache.
the class LoaderSF method store.
/**
* Store the only the Loader elements, when not default
*
* @see NamingResourcesSF#storeChildren(PrintWriter, int, Object, StoreDescription)
*/
@Override
public void store(PrintWriter aWriter, int indent, Object aElement) throws Exception {
StoreDescription elementDesc = getRegistry().findDescription(aElement.getClass());
if (elementDesc != null) {
Loader loader = (Loader) aElement;
if (!isDefaultLoader(loader)) {
if (log.isDebugEnabled())
log.debug("store " + elementDesc.getTag() + "( " + aElement + " )");
getStoreAppender().printIndent(aWriter, indent + 2);
getStoreAppender().printTag(aWriter, indent + 2, loader, elementDesc);
}
} else {
if (log.isWarnEnabled()) {
log.warn("Descriptor for element" + aElement.getClass() + " not configured or element class not StandardManager!");
}
}
}
use of org.apache.catalina.Loader in project tomee by apache.
the class TomcatWebAppBuilder method configuredClasspath.
private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
Loader loader = standardContext.getLoader();
if (loader != null && LazyStopLoader.class.isInstance(loader)) {
loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
}
if (loader != null) {
final ClassLoader cl = standardContext.getLoader().getClassLoader();
if (cl == null) {
return null;
}
final Collection<String> cp = new LinkedList<>();
final WebResourceRoot webResources = standardContext.getResources();
if (webResources != null) {
// to enhance
for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
for (final WebResourceSet wr : sets) {
final URL base = wr.getBaseUrl();
if (base != null) {
final File baseFile = URLs.toFile(base);
if (baseFile.isDirectory()) {
final String[] libs = wr.list("/WEB-INF/lib/");
if (libs != null) {
for (final String resource : libs) {
cp.add(new File(baseFile, resource).getAbsolutePath());
}
}
final WebResource classes = wr.getResource("/WEB-INF/classes/");
if (classes != null) {
final String path = classes.getCanonicalPath();
if (path != null) {
cp.add(path);
}
}
} else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
try {
cp.add(baseFile.getCanonicalPath());
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
}
}
}
}
if (!cp.isEmpty()) {
return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null);
}
}
return null;
}
Aggregations