You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/12/10 14:14:49 UTC

[myfaces] branch master updated: MYFACES-4274 Lookup ExpressionFactory, also if SUPPORT_JSP_AND_FACES_EL is false

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new c7dbf03  MYFACES-4274 Lookup ExpressionFactory, also if SUPPORT_JSP_AND_FACES_EL is false
c7dbf03 is described below

commit c7dbf03f16768a0a58dc4c4ad833e7e548a5348f
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Dec 10 15:14:38 2018 +0100

    MYFACES-4274 Lookup ExpressionFactory, also if SUPPORT_JSP_AND_FACES_EL is false
---
 .../el/unified/ResolverBuilderForFaces.java        | 26 ++-----
 .../myfaces/webapp/AbstractFacesInitializer.java   |  5 ++
 .../myfaces/webapp/FaceletsInitilializer.java      | 26 ++++++-
 .../autoLookupExpressionFactoryWithoutJSP/pom.xml  | 35 ++++++++++
 .../core/integrationtests/IntegrationTestBean.java | 36 ++++++++++
 .../src/main/webapp/WEB-INF/beans.xml              | 25 +++++++
 .../src/main/webapp/WEB-INF/web.xml                | 48 +++++++++++++
 .../src/main/webapp/index.xhtml                    | 38 ++++++++++
 .../core/integrationtests/IntegrationTest.java     | 80 ++++++++++++++++++++++
 .../src/test/resources/arquillian.xml              | 37 ++++++++++
 integration-tests/pom.xml                          |  1 +
 11 files changed, 336 insertions(+), 21 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java b/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
index 8472014..dee300d 100644
--- a/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
+++ b/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
@@ -68,18 +68,11 @@ public class ResolverBuilderForFaces extends ResolverBuilderBase implements ELRe
             staticFieldELResolverClass = ClassUtils.classForName("javax.el.StaticFieldELResolver");
             getStreamELResolverMethod = ExpressionFactory.class.getMethod("getStreamELResolver");
         }
-        catch (NoSuchMethodException ex)
-        {
-            //No op
-        }
-        catch (SecurityException ex)
-        {
-            //No op
-        }
-        catch (ClassNotFoundException ex)
+        catch (NoSuchMethodException | SecurityException | ClassNotFoundException ex)
         {
             //No op
         }
+
         STATIC_FIELD_EL_RESOLVER_CLASS = staticFieldELResolverClass;
         GET_STREAM_EL_RESOLVER_METHOD = getStreamELResolverMethod;
     }
@@ -89,6 +82,7 @@ public class ResolverBuilderForFaces extends ResolverBuilderBase implements ELRe
         super(config);
     }
 
+    @Override
     public void build(CompositeELResolver compositeElResolver)
     {
         build(FacesContext.getCurrentInstance(), compositeElResolver);
@@ -144,16 +138,10 @@ public class ResolverBuilderForFaces extends ResolverBuilderBase implements ELRe
                 }
                 list.add((ELResolver) STATIC_FIELD_EL_RESOLVER_CLASS.newInstance());
             } 
-            catch (IllegalAccessException ex)
-            {
-            }
-            catch (IllegalArgumentException ex)
-            {
-            }
-            catch (InvocationTargetException ex)
-            {
-            }
-            catch (InstantiationException ex)
+            catch (IllegalAccessException
+                    | IllegalArgumentException
+                    | InvocationTargetException
+                    | InstantiationException ex)
             {
             }
         }
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
index 7046f10..6a77f5b 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -469,6 +469,11 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
      */
     protected static ExpressionFactory loadExpressionFactory(String expressionFactoryClassName)
     {
+        return loadExpressionFactory(expressionFactoryClassName, true);
+    }
+    
+    protected static ExpressionFactory loadExpressionFactory(String expressionFactoryClassName, boolean logMissing)
+    {
         try
         {
             ClassLoader cl = ClassUtils.getContextClassLoader();
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java b/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
index 1bb0200..aa4be22 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.webapp;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.el.ExpressionFactory;
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
@@ -31,18 +33,38 @@ import javax.servlet.ServletContext;
  */
 public class FaceletsInitilializer extends org.apache.myfaces.webapp.AbstractFacesInitializer
 {
+    private static final Logger log = Logger.getLogger(FaceletsInitilializer.class.getName());
 
     @Override
     protected void initContainerIntegration(ServletContext servletContext, ExternalContext externalContext)
     {
-
         ExpressionFactory expressionFactory = getUserDefinedExpressionFactory(externalContext);
         if (expressionFactory == null)
         {
+            String[] candidates = new String[] { "org.apache.el.ExpressionFactoryImpl",
+                "com.sun.el.ExpressionFactoryImpl", "de.odysseus.el.ExpressionFactoryImpl",
+                "org.jboss.el.ExpressionFactoryImpl", "com.caucho.el.ExpressionFactoryImpl" };
+            
+            for (String candidate : candidates)
+            {
+                expressionFactory = loadExpressionFactory(candidate, false);
+                if (expressionFactory != null)
+                {
+                    if (log.isLoggable(Level.FINE))
+                    {
+                        log.fine("javax.el.ExpressionFactory implementation found: " + candidate);
+                    }
+                    break;
+                }
+            }
+        }
+
+        if (expressionFactory == null)
+        {
             throw new FacesException("No javax.el.ExpressionFactory found. Please provide" +
                     " <context-param> in web.xml: org.apache.myfaces.EXPRESSION_FACTORY");
         }
-
+        
         buildConfiguration(servletContext, externalContext, expressionFactory);
     }
 
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/pom.xml b/integration-tests/autoLookupExpressionFactoryWithoutJSP/pom.xml
new file mode 100644
index 0000000..6391a4c
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/pom.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
+        <groupId>org.apache.myfaces.core</groupId>
+        <artifactId>myfaces-integration-tests</artifactId>
+        <version>3.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.myfaces.core.integration-tests</groupId>
+    <artifactId>autoLookupExpressionFactoryWithoutJSP</artifactId>
+    <name>Apache MyFaces Core 3.0 - Integration Tests - autoLookupExpressionFactoryWithoutJSP</name>
+    <packaging>war</packaging>
+
+</project>
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/java/org/apache/myfaces/core/integrationtests/IntegrationTestBean.java b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/java/org/apache/myfaces/core/integrationtests/IntegrationTestBean.java
new file mode 100644
index 0000000..ead2733
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/java/org/apache/myfaces/core/integrationtests/IntegrationTestBean.java
@@ -0,0 +1,36 @@
+/*
+ * 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.myfaces.core.integrationtests;
+
+import static javax.faces.annotation.FacesConfig.Version.JSF_2_3;
+
+import javax.enterprise.context.RequestScoped;
+import javax.faces.annotation.FacesConfig;
+import javax.inject.Named;
+
+@FacesConfig(version = JSF_2_3)
+@Named
+@RequestScoped
+public class IntegrationTestBean
+{
+    public String getMessage()
+    {
+        return "EL works!";
+    }
+}
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/WEB-INF/beans.xml b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..9bcebd8
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+       version="1.2" bean-discovery-mode="all">
+
+</beans>
\ No newline at end of file
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/WEB-INF/web.xml b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..7395030
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+         version="3.1">
+
+    <context-param>
+        <param-name>javax.faces.PROJECT_STAGE</param-name>
+        <param-value>Production</param-value>
+    </context-param>
+    <context-param>
+        <param-name>org.apache.myfaces.LOG_WEB_CONTEXT_PARAMS</param-name>
+        <param-value>false</param-value>
+    </context-param>
+    <context-param>
+        <param-name>org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL</param-name>
+        <param-value>false</param-value>
+    </context-param>
+
+    <listener>
+        <listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
+    </listener>
+    <listener>
+        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
+    </listener>
+
+    <session-config>
+        <tracking-mode>COOKIE</tracking-mode>
+    </session-config>
+</web-app>
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/index.xhtml b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/index.xhtml
new file mode 100644
index 0000000..5c73cde
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/main/webapp/index.xhtml
@@ -0,0 +1,38 @@
+<!--
+    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.
+-->
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:h="http://xmlns.jcp.org/jsf/html"
+      xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
+      xmlns:f="http://xmlns.jcp.org/jsf/core"
+      xmlns:jsf="http://xmlns.jcp.org/jsf"
+      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+
+    <h:head>
+        <title>test</title>
+    </h:head>
+
+    <h:body>
+        <h:form>
+            #{integrationTestBean.message}
+        </h:form>
+    </h:body>
+
+</html>
+
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/test/java/org/apache/myfaces/core/integrationtests/IntegrationTest.java b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/test/java/org/apache/myfaces/core/integrationtests/IntegrationTest.java
new file mode 100644
index 0000000..0c7eed0
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/test/java/org/apache/myfaces/core/integrationtests/IntegrationTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.myfaces.core.integrationtests;
+
+import java.io.File;
+import java.net.URL;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.drone.api.annotation.Drone;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.embedded.EmbeddedMaven;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openqa.selenium.WebDriver;
+
+@RunWith(Arquillian.class)
+@RunAsClient
+public class IntegrationTest
+{
+    @Deployment(testable = false)
+    public static WebArchive createDeployment()
+    {
+        WebArchive webArchive = (WebArchive) EmbeddedMaven.forProject(new File("pom.xml"))
+                .useMaven3Version("3.3.9")
+                .setGoals("package")
+                .setQuiet()
+                .skipTests(true)
+                .ignoreFailure()
+                .build().getDefaultBuiltArchive();
+
+        return webArchive;
+    }
+
+    @Drone
+    protected WebDriver webDriver;
+
+    @ArquillianResource
+    protected URL contextPath;
+
+    @Before
+    public void before()
+    {
+    }
+
+    @After
+    public void after()
+    {
+        webDriver.manage().deleteAllCookies();
+    }
+
+    @Test
+    public void test()
+    {
+        webDriver.get(contextPath + "index.xhtml");
+
+        Assert.assertTrue(webDriver.getPageSource().contains("ViewState"));
+        Assert.assertTrue(webDriver.getPageSource().contains("EL works!"));
+    }
+}
diff --git a/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/test/resources/arquillian.xml b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..df569d2
--- /dev/null
+++ b/integration-tests/autoLookupExpressionFactoryWithoutJSP/src/test/resources/arquillian.xml
@@ -0,0 +1,37 @@
+<!--
+    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.
+-->
+<arquillian
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"
+    xmlns="http://jboss.org/schema/arquillian">
+
+    <extension qualifier="webdriver">
+        <property name="browser">chrome</property>
+    </extension>
+
+    <container qualifier="tomcat" default="true">
+        <configuration>
+            <property name="tomcatHome">target/tomcat-embedded-8</property>
+            <property name="workDir">work</property>
+            <property name="bindHttpPort">8888</property>
+            <property name="unpackArchive">true</property>
+            <property name="serverName">arquillian-tomcat-embedded-8</property>
+        </configuration>
+    </container>
+</arquillian>
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index c2c0d14..fadabfa 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -165,6 +165,7 @@
         <module>faceletToXhtmlMapping</module>
         <module>faceletToXhtmlMappingDisabled</module>
         <module>exactMapping</module>
+        <module>autoLookupExpressionFactoryWithoutJSP</module>
     </modules>
 
     <profiles>