Author: rmannibucau
Date: Fri Aug 10 13:15:49 2012
New Revision: 1371694
URL: http://svn.apache.org/viewvc?rev=1371694&view=rev
Log:
some more exclusions, and a custom FacesConfigResourceProvider to avoid to scan
the whole app libs to find file ending with .faces-config.xml (now myfaces
check if it should start for each app), adding a property to skip jsf auto
startup openejb.jsf.skip = true)
Added:
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProviderFactory.java
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigResourceProviderFactory
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/resources/default.exclusions
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/resources/default.exclusions
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/resources/default.exclusions?rev=1371694&r1=1371693&r2=1371694&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/resources/default.exclusions
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/resources/default.exclusions
Fri Aug 10 13:15:49 2012
@@ -59,7 +59,9 @@ groovy-
gson
guice-
hamcrest-
+hawtbuf-
hawtdispatch-
+hawtjni-runtime
hibernate-
howl-
hsqldb-
@@ -112,6 +114,7 @@ neethi-
nekohtml-
openejb-api
openejb-client
+openejb-core
openejb-cxf
openejb-cxf-rs
openejb-cxf-bundle
Added:
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java?rev=1371694&view=auto
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
(added)
+++
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java
Fri Aug 10 13:15:49 2012
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.myfaces;
+
+import org.apache.myfaces.config.DefaultFacesConfigResourceProvider;
+import org.apache.myfaces.shared.util.ClassUtils;
+import org.apache.openejb.config.NewLoaderLogic;
+import org.apache.openejb.loader.Files;
+import org.apache.openejb.util.URLs;
+import org.apache.xbean.finder.UrlSet;
+
+import javax.faces.context.ExternalContext;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Pattern;
+
+public class TomEEFacesConfigResourceProvider extends
DefaultFacesConfigResourceProvider {
+ private static final String META_INF_PREFIX = "META-INF/";
+ private static final String FACES_CONFIG_SUFFIX = ".faces-config.xml";
+ private static final String FACES_CONFIG_IMPLICIT =
"META-INF/faces-config.xml";
+ private static final Pattern FILE_PATTERN = Pattern.compile("^.*" +
Pattern.quote(FACES_CONFIG_SUFFIX) + "$");
+
+ @Override
+ public Collection<URL> getMetaInfConfigurationResources(final
ExternalContext context) throws IOException {
+ final List<URL> urlSet = new ArrayList<URL>();
+ final ClassLoader loader = getClassLoader();
+
+ final Enumeration<URL> resources =
loader.getResources(FACES_CONFIG_IMPLICIT);
+ while (resources.hasMoreElements()) {
+ urlSet.add(resources.nextElement());
+ }
+
+ // Scan files inside META-INF ending with .faces-config.xml
+ for (URL url : NewLoaderLogic.applyBuiltinExcludes(new
UrlSet(loader)).getUrls()) {
+ final File file = URLs.toFile(url);
+ if (!file.exists()) {
+ continue;
+ }
+
+ if (!file.isDirectory()) { // browse all entries to see if we have
a matching file
+ final Enumeration<JarEntry> e = new JarFile(file).entries();
+ while (e.hasMoreElements()) {
+ try {
+ final String name = e.nextElement().getName();
+ if (name.startsWith(META_INF_PREFIX) &&
name.endsWith(FACES_CONFIG_SUFFIX)) {
+ final Enumeration<URL> e2 =
loader.getResources(name);
+ while (e2.hasMoreElements()) {
+ urlSet.add(e2.nextElement());
+ }
+ }
+ } catch (Throwable ignored) {
+ // no-op
+ }
+ }
+ } else {
+ final File metaInf = new File(file, META_INF_PREFIX);
+ if (metaInf.exists() && metaInf.isDirectory()) {
+ for (File f : Files.collect(metaInf, FILE_PATTERN)) {
+ urlSet.add(f.toURI().toURL());
+ }
+ }
+ }
+ }
+
+ return urlSet;
+ }
+
+ private ClassLoader getClassLoader() {
+ ClassLoader loader = ClassUtils.getContextClassLoader();
+ if (loader == null) {
+ loader = this.getClass().getClassLoader();
+ }
+ return loader;
+ }
+}
Added:
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProviderFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProviderFactory.java?rev=1371694&view=auto
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProviderFactory.java
(added)
+++
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProviderFactory.java
Fri Aug 10 13:15:49 2012
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomee.myfaces;
+
+import org.apache.myfaces.shared.util.ClassUtils;
+import org.apache.myfaces.spi.FacesConfigResourceProvider;
+import org.apache.myfaces.spi.ServiceProviderFinderFactory;
+import org.apache.myfaces.spi.impl.DefaultFacesConfigResourceProviderFactory;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class TomEEFacesConfigResourceProviderFactory extends
DefaultFacesConfigResourceProviderFactory {
+ private Logger getLogger() {
+ return
Logger.getLogger(TomEEFacesConfigResourceProviderFactory.class.getName());
+ }
+
+ @Override
+ public FacesConfigResourceProvider createFacesConfigResourceProvider(final
ExternalContext externalContext) {
+ FacesConfigResourceProvider returnValue = null;
+ try {
+ if (System.getSecurityManager() != null) {
+ returnValue = AccessController.doPrivileged(new
PrivilegedExceptionAction<FacesConfigResourceProvider>() {
+ public FacesConfigResourceProvider run() throws Exception {
+ return
resolveFacesConfigResourceProviderFromService(externalContext);
+ }
+ });
+ } else {
+ returnValue =
resolveFacesConfigResourceProviderFromService(externalContext);
+ }
+ } catch (ClassNotFoundException e) {
+ // ignore
+ } catch (NoClassDefFoundError e) {
+ // ignore
+ } catch (InstantiationException e) {
+ getLogger().log(Level.SEVERE, "", e);
+ } catch (IllegalAccessException e) {
+ getLogger().log(Level.SEVERE, "", e);
+ } catch (InvocationTargetException e) {
+ getLogger().log(Level.SEVERE, "", e);
+ } catch (PrivilegedActionException e) {
+ throw new FacesException(e);
+ }
+ return returnValue;
+ }
+
+ private FacesConfigResourceProvider
resolveFacesConfigResourceProviderFromService(final ExternalContext
externalContext)
+ throws ClassNotFoundException, NoClassDefFoundError,
InstantiationException,
+ IllegalAccessException, InvocationTargetException,
PrivilegedActionException {
+ List<String> classList = (List<String>)
externalContext.getApplicationMap().get(FACES_CONFIG_PROVIDER_LIST);
+ if (classList == null) {
+ classList =
ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).
+ getServiceProviderList(FACES_CONFIG_PROVIDER);
+
externalContext.getApplicationMap().put(FACES_CONFIG_PROVIDER_LIST, classList);
+ }
+ return
ClassUtils.buildApplicationObject(FacesConfigResourceProvider.class, classList,
new TomEEFacesConfigResourceProvider());
+ }
+}
Modified:
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java?rev=1371694&r1=1371693&r2=1371694&view=diff
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java
(original)
+++
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java
Fri Aug 10 13:15:49 2012
@@ -4,6 +4,7 @@ import org.apache.myfaces.context.servle
import org.apache.myfaces.ee6.MyFacesContainerInitializer;
import org.apache.myfaces.spi.FacesConfigResourceProvider;
import org.apache.myfaces.spi.FacesConfigResourceProviderFactory;
+import org.apache.openejb.loader.SystemInstance;
import javax.faces.context.ExternalContext;
import javax.faces.webapp.FacesServlet;
@@ -13,10 +14,13 @@ import javax.servlet.ServletException;
import java.io.File;
import java.net.URL;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class TomEEMyFacesContainerInitializer implements
ServletContainerInitializer {
+ public static final String OPENEJB_JSF_SKIP = "openejb.jsf.skip";
+
private final MyFacesContainerInitializer delegate;
public TomEEMyFacesContainerInitializer() {
@@ -26,11 +30,24 @@ public class TomEEMyFacesContainerInitia
@Override
public void onStartup(final Set<Class<?>> classes, final ServletContext
ctx) throws ServletException {
// try to skip first
- if
("true".equalsIgnoreCase(ctx.getInitParameter("org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE")))
{
+ if
("true".equalsIgnoreCase(ctx.getInitParameter("org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE"))
+ ||
"true".equals(SystemInstance.get().getProperty(OPENEJB_JSF_SKIP, "false"))) {
return;
}
if ((classes != null && !classes.isEmpty()) ||
isFacesConfigPresent(ctx)) {
// we found a faces-config.xml or some classes so let's delegate
to myfaces
+
+ // since we don't want to call isFacesConfigPresent again (it scan
all jars!!!!)
+ // forcing classes to not be empty
+ Set<Class<?>> passedClasses = classes;
+ if (passedClasses == null) {
+ passedClasses = new HashSet<Class<?>>();
+ }
+ if (passedClasses.isEmpty()) {
+ passedClasses.add(TomEEMyFacesContainerInitializer.class);
+ }
+
+ // finally delegating begin sure we'll not call
isFacesConfigPresent
delegate.onStartup(classes, ctx);
}
}
Added:
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigResourceProviderFactory
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigResourceProviderFactory?rev=1371694&view=auto
==============================================================================
---
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigResourceProviderFactory
(added)
+++
openejb/trunk/openejb/tomee/tomee-myfaces/src/main/resources/META-INF/services/org.apache.myfaces.spi.FacesConfigResourceProviderFactory
Fri Aug 10 13:15:49 2012
@@ -0,0 +1 @@
+org.apache.tomee.myfaces.TomEEFacesConfigResourceProviderFactory