Author: rmannibucau Date: Thu Feb 14 21:06:29 2013 New Revision: 1446327 URL: http://svn.apache.org/r1446327 Log: jsf classes should be loaded from the right classloader + mysql connector exclusion
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/WebappAggregatedArchive.java tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java tomee/tomee/trunk/container/openejb-core/src/main/resources/default.exclusions tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Thu Feb 14 21:06:29 2013 @@ -409,6 +409,14 @@ public class AnnotationDeployer implemen public static class DiscoverAnnotatedBeans implements DynamicDeployer { public AppModule deploy(AppModule appModule) throws OpenEJBException { + if (!appModule.isWebapp()) { + try { + appModule.setEarLibFinder(FinderFactory.createFinder(appModule)); + } catch (final Exception e) { + logger.error("Can't create a finder for ear libs", e); + } + } + for (EjbModule ejbModule : appModule.getEjbModules()) { ejbModule.initAppModule(appModule); setModule(ejbModule); @@ -1114,12 +1122,7 @@ public class AnnotationDeployer implemen IAnnotationFinder parentFinder = null; final AppModule appModule = webModule.getAppModule(); if (appModule != null) { - for (final EjbModule module : appModule.getEjbModules()) { - if (!module.getModuleId().startsWith(DeploymentLoader.EAR_SCOPED_CDI_BEANS)) { - parentFinder = module.getFinder(); - break; - } - } + parentFinder = appModule.getEarLibFinder(); } final ClassLoader classLoader = webModule.getClassLoader(); Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java Thu Feb 14 21:06:29 2013 @@ -23,6 +23,7 @@ import org.apache.openejb.jee.jpa.unit.P import org.apache.openejb.jee.jpa.unit.PersistenceUnit; import org.apache.openejb.jee.jpa.unit.TransactionType; import org.apache.openejb.util.SuperProperties; +import org.apache.xbean.finder.IAnnotationFinder; import java.io.File; import java.net.URI; @@ -64,6 +65,7 @@ public class AppModule implements Deploy private final Set<String> additionalLibMbeans = new TreeSet<String>(); private final Collection<String> jaxRsProviders = new TreeSet<String>(); private final Map<String, PojoConfiguration> pojoConfigurations = new HashMap<String, PojoConfiguration>(); + private IAnnotationFinder earLibFinder = null; private ID id; private boolean webapp = false; @@ -349,4 +351,12 @@ public class AppModule implements Deploy public Map<String, PojoConfiguration> getPojoConfigurations() { return pojoConfigurations; } + + public IAnnotationFinder getEarLibFinder() { + return earLibFinder; + } + + public void setEarLibFinder(final IAnnotationFinder earLibFinder) { + this.earLibFinder = earLibFinder; + } } Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java Thu Feb 14 21:06:29 2013 @@ -21,6 +21,7 @@ import org.apache.openejb.loader.SystemI import org.apache.xbean.finder.Annotated; import org.apache.xbean.finder.AnnotationFinder; import org.apache.xbean.finder.IAnnotationFinder; +import org.apache.xbean.finder.UrlSet; import org.apache.xbean.finder.archive.Archive; import org.apache.xbean.finder.archive.ClassesArchive; import org.apache.xbean.finder.archive.ClasspathArchive; @@ -34,6 +35,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -65,6 +67,9 @@ public class FinderFactory { } else if (module instanceof ConnectorModule) { ConnectorModule connectorModule = (ConnectorModule) module; finder = new AnnotationFinder(new ConfigurableClasspathArchive(connectorModule, connectorModule.getLibraries())).link(); + } else if (module instanceof AppModule) { + final Collection<URL> urls = NewLoaderLogic.applyBuiltinExcludes(new UrlSet(module.getClassLoader())).getUrls(); + finder = new AnnotationFinder(new WebappAggregatedArchive(module.getClassLoader(), module.getAltDDs(), urls)); } else if (module.getJarLocation() != null) { String location = module.getJarLocation(); File file = new File(location); Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/WebappAggregatedArchive.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/WebappAggregatedArchive.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/WebappAggregatedArchive.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/WebappAggregatedArchive.java Thu Feb 14 21:06:29 2013 @@ -26,6 +26,7 @@ import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -60,7 +61,7 @@ public class WebappAggregatedArchive imp archive = new CompositeArchive(archives); } - public WebappAggregatedArchive(final ClassLoader classLoader, final Map<String, Object> altDDs, ArrayList<URL> xmls) { + public WebappAggregatedArchive(final ClassLoader classLoader, final Map<String, Object> altDDs, Collection<URL> xmls) { this(new ConfigurableClasspathArchive.FakeModule(classLoader, altDDs), xmls); } Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/TempClassLoader.java Thu Feb 14 21:06:29 2013 @@ -102,7 +102,7 @@ public class TempClassLoader extends URL * 2. Since this class loader uses Class.forName to load classes starting with java, javax or sun, it cannot load javax.faces.FacesServlet * 3. Result is , AnnotationDeployer throws a ClassNotFoundException */ - if (this.skip(name)) { + if (this.skip(name) || (name.startsWith("javax.faces.") && URLClassLoaderFirst.shouldSkipJsf(getParent(), name))) { return Class.forName(name, resolve, this.getClass().getClassLoader()); } Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java Thu Feb 14 21:06:29 2013 @@ -16,6 +16,7 @@ */ package org.apache.openejb.util.classloader; +import org.apache.openejb.core.TempClassLoader; import org.apache.openejb.loader.SystemInstance; import java.io.IOException; @@ -100,7 +101,7 @@ public class URLClassLoaderFirst extends } // look for it in this classloader - boolean ok = !shouldSkip(name); + boolean ok = !(shouldSkip(name) || (name.startsWith("javax.faces.") && URLClassLoaderFirst.shouldSkipJsf(this, name))); if (ok) { clazz = loadInternal(name, resolve); if (clazz != null) { @@ -319,6 +320,33 @@ public class URLClassLoaderFirst extends return false; } + public static boolean shouldSkipJsf(final ClassLoader loader, final String name) { + ClassLoader parentLoader = loader.getParent(); + while (parentLoader != null && TempClassLoader.class.isInstance(parentLoader) && URLClassLoaderFirst.class.getClassLoader() != parentLoader) { + parentLoader = parentLoader.getParent(); + } + if (parentLoader == null) { + return true; + } + + // using annotation to test to avoid to load more classes with deps + final String testClass; + if ("javax.faces.bean.RequestScoped".equals(name)) { + testClass = "javax.faces.bean.SessionScoped"; + } else { + testClass = "javax.faces.bean.RequestScoped"; + } + + final String classname = testClass.replace('.', '/') + ".class"; + final URL thisJSf = loader.getResource(classname); + if (thisJSf == null) { + return true; + } + final URL containerJsf = loader.getResource(classname); + return containerJsf != null && thisJSf.equals(containerJsf); + + } + // in org.apache.openejb. private static boolean isWebAppEnrichment(final String openejb) { return openejb.startsWith("hibernate.") || openejb.startsWith("jpa.integration.") Modified: tomee/tomee/trunk/container/openejb-core/src/main/resources/default.exclusions URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/resources/default.exclusions?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/resources/default.exclusions (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/resources/default.exclusions Thu Feb 14 21:06:29 2013 @@ -126,6 +126,7 @@ mina- mqtt-client- myfaces-api myfaces-impl +mysql-connector-java- neethi- nekohtml- openejb-api Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java (original) +++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java Thu Feb 14 21:06:29 2013 @@ -86,7 +86,7 @@ public class LazyStopWebappClassLoader e } // avoid to redefine classes from server in this classloader is it not already loaded - if (URLClassLoaderFirst.shouldSkip(name)) { + if (URLClassLoaderFirst.shouldSkip(name) || (name.startsWith("javax.faces.") && URLClassLoaderFirst.shouldSkipJsf(this, name))) { try { return OpenEJB.class.getClassLoader().loadClass(name); } catch (ClassNotFoundException e) { Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1446327&r1=1446326&r2=1446327&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java (original) +++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Thu Feb 14 21:06:29 2013 @@ -1662,7 +1662,7 @@ public class TomcatWebAppBuilder impleme } private boolean isUnDeployable(final ContextInfo contextInfo) { - return contextInfo != null && contextInfo.appInfo != null && contextInfo.deployer == null + return contextInfo != null && contextInfo.appInfo != null && contextInfo.deployer == null && contextInfo.appInfo.webAppAlone && getAssembler().getDeployedApplications().contains(contextInfo.appInfo); } @@ -1708,7 +1708,9 @@ public class TomcatWebAppBuilder impleme } ClassLoaderUtil.cleanOpenJPACache(old); } - removeContextInfo(standardContext); + if (contextInfo.appInfo == null || contextInfo.appInfo.webAppAlone) { + removeContextInfo(standardContext); + } } /**