@Override public Enumeration<URL> getResources(final String name) throws IOException { if (!getState().isAvailable()) { return null; } if ("META-INF/services/javax.servlet.ServletContainerInitializer".equals(name)) { final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name))); final Iterator<URL> it = list.iterator(); while (it.hasNext()) { final URL next = it.next(); final File file = Files.toFile(next); if (!file.isFile() && NewLoaderLogic.skip(next)) { it.remove(); } } return Collections.enumeration(list); } if ("META-INF/services/javax.websocket.ContainerProvider".equals(name)) { final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name))); final Iterator<URL> it = list.iterator(); while (it.hasNext()) { final URL next = it.next(); final File file = Files.toFile(next); if (!file.isFile() && NewLoaderLogic.skip(next)) { it.remove(); } } return Collections.enumeration(list); } if ("META-INF/faces-config.xml".equals(name)) { // mojarra workaround try { if (WebBeansContext.currentInstance() == null && Boolean.parseBoolean( SystemInstance.get().getProperty("tomee.jsf.ignore-owb", "true"))) { final Collection<URL> list = new HashSet<>(Collections.list(super.getResources(name))); final Iterator<URL> it = list.iterator(); while (it.hasNext()) { final String fileName = Files.toFile(it.next()).getName(); if (fileName.startsWith("openwebbeans-" /*jsf|el22*/) && fileName.endsWith(".jar")) { it.remove(); } } return Collections.enumeration(list); } } catch (final Throwable th) { // no-op } } return URLClassLoaderFirst.filterResources(name, super.getResources(name)); }
@Override protected boolean filter(final String inName, final boolean isClassName) { final String name = inName == null || isClassName ? inName : inName.replace('/', '.').replace(".class", ""); if ("org.apache.tomee.mojarra.TomEEInjectionProvider".equals(name)) { return false; } if (isEar) { // check we are called from super and we already cached the result in loadClass synchronized (this) { final Boolean cache = filterTempCache.get(name); if (cache != null) { return cache; } } } return URLClassLoaderFirst.shouldSkip(name); }
@Override public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if ("org.apache.openejb.hibernate.OpenEJBJtaPlatform".equals(name) || "org.apache.openejb.jpa.integration.hibernate.PrefixNamingStrategy".equals(name) || "org.apache.openejb.jpa.integration.eclipselink.PrefixSessionCustomizer".equals(name) || "org.apache.openejb.jpa.integration.eclipselink.OpenEJBServerPlatform".equals(name) || "org.apache.openejb.jpa.integration.eclipselink.OpenEJBServerPlatform$OpenEJBJTATransactionController" .equals(name) || "org.apache.openejb.eclipselink.JTATransactionController".equals(name) || "org.apache.tomee.mojarra.TomEEInjectionProvider".equals(name)) { // don't load them from system classloader (breaks all in embedded mode and no sense in other // cases) synchronized (this) { final ClassLoader old = getJavaseClassLoader(); setJavaseClassLoader(NoClassClassLoader.INSTANCE); delegate = false; try { return super.loadClass(name, resolve); } finally { setJavaseClassLoader(old); setDelegate(originalDelegate); } } } // avoid to redefine classes from server in this classloader is it not already loaded if (URLClassLoaderFirst.shouldDelegateToTheContainer( this, name)) { // dynamic validation handling overriding try { return OpenEJB.class .getClassLoader() .loadClass( name); // we could use containerClassLoader but this is server loader so cut it even // more } catch (final ClassNotFoundException e) { synchronized (this) { return super.loadClass(name, resolve); } } catch (final NoClassDefFoundError ncdfe) { synchronized (this) { return super.loadClass(name, resolve); } } } else if (name.startsWith("javax.faces.") || name.startsWith("org.apache.webbeans.jsf")) { synchronized (this) { delegate = false; try { return super.loadClass(name, resolve); } finally { setDelegate(originalDelegate); } } } synchronized ( this) { // TODO: rework it to avoid it and get aligned on Java 7 classloaders (but not a big // issue) if (isEar) { final boolean filter = filter(name, true); filterTempCache.put(name, filter); // will be called again by super.loadClass() so cache it if (!filter) { if (URLClassLoaderFirst.class.isInstance(getParent())) { // true final URLClassLoaderFirst urlClassLoaderFirst = URLClassLoaderFirst.class.cast(getParent()); Class<?> c = urlClassLoaderFirst.findAlreadyLoadedClass(name); if (c != null) { return c; } c = urlClassLoaderFirst.loadInternal(name, resolve); if (c != null) { return c; } } return loadWithDelegate( getResource(name.replace('.', '/') + CLASS_EXTENSION) == null, resolve, name); } } return super.loadClass(name, resolve); } }