Search in sources :

Example 16 with Loader

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;
}
Also used : ThreadBindingListener(org.apache.catalina.ThreadBindingListener) PrivilegedGetTccl(org.apache.tomcat.util.security.PrivilegedGetTccl) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) PrivilegedSetTccl(org.apache.tomcat.util.security.PrivilegedSetTccl)

Example 17 with Loader

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 };
    }
}
Also used : Loader(org.apache.catalina.Loader)

Example 18 with Loader

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() };
    }
}
Also used : Loader(org.apache.catalina.Loader)

Example 19 with Loader

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!");
        }
    }
}
Also used : Loader(org.apache.catalina.Loader) WebappLoader(org.apache.catalina.loader.WebappLoader)

Example 20 with Loader

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;
}
Also used : WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) DeploymentLoader(org.apache.openejb.config.DeploymentLoader) WebResource(org.apache.catalina.WebResource) IOException(java.io.IOException) LinkedList(java.util.LinkedList) URL(java.net.URL) WebResourceSet(org.apache.catalina.WebResourceSet) File(java.io.File) JarFile(java.util.jar.JarFile) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Aggregations

Loader (org.apache.catalina.Loader)26 WebappLoader (org.apache.catalina.loader.WebappLoader)13 LifecycleException (org.apache.catalina.LifecycleException)10 IOException (java.io.IOException)9 Container (org.apache.catalina.Container)6 File (java.io.File)5 ObjectInputStream (java.io.ObjectInputStream)5 MalformedURLException (java.net.MalformedURLException)5 Lifecycle (org.apache.catalina.Lifecycle)5 Manager (org.apache.catalina.Manager)5 NamingException (javax.naming.NamingException)4 ServletException (javax.servlet.ServletException)4 Realm (org.apache.catalina.Realm)4 WebResourceRoot (org.apache.catalina.WebResourceRoot)4 StandardManager (org.apache.catalina.session.StandardManager)4 CustomObjectInputStream (org.apache.catalina.util.CustomObjectInputStream)4 DeploymentLoader (org.apache.openejb.config.DeploymentLoader)4 InstanceManager (org.apache.tomcat.InstanceManager)4 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3