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 2021/11/29 16:11:08 UTC
[myfaces] branch master updated: MYFACES-4422
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 bc09409 MYFACES-4422
bc09409 is described below
commit bc094092a5c310ae17f5509fb377ab468c782208
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Mon Nov 29 17:11:02 2021 +0100
MYFACES-4422
---
.../application/FacesServletMappingUtils.java | 17 ++--
.../myfaces/webapp/FacesInitializerImpl.java | 4 +-
.../automaticExtensionlessMapping/pom.xml | 36 ++++++++
.../core/integrationtests/IntegrationTestBean.java | 33 ++++++++
.../src/main/webapp/WEB-INF/beans.xml | 25 ++++++
.../src/main/webapp/WEB-INF/web.xml | 58 +++++++++++++
.../src/main/webapp/bar.xhtml | 37 ++++++++
.../src/main/webapp/foo.xhtml | 37 ++++++++
.../core/integrationtests/IntegrationTest.java | 99 ++++++++++++++++++++++
.../src/test/resources/arquillian.xml | 37 ++++++++
integration-tests/pom.xml | 1 +
11 files changed, 374 insertions(+), 10 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java b/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java
index 67b02b2..99389f1 100644
--- a/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java
+++ b/impl/src/main/java/org/apache/myfaces/application/FacesServletMappingUtils.java
@@ -30,6 +30,7 @@ import jakarta.faces.webapp.FacesServlet;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRegistration;
import org.apache.myfaces.config.MyfacesConfig;
+import org.apache.myfaces.context.servlet.StartupFacesContextImpl;
import org.apache.myfaces.util.lang.ClassUtils;
import org.apache.myfaces.util.ExternalContextUtils;
import org.apache.myfaces.webapp.DelegatedFacesServlet;
@@ -107,7 +108,7 @@ public class FacesServletMappingUtils
}
public static List<ServletRegistrationInfo> getServletRegistrations(FacesContext facesContext,
- ServletContext servletContext, boolean cache)
+ ServletContext servletContext)
{
Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
@@ -130,7 +131,7 @@ public class FacesServletMappingUtils
}
infos = Collections.unmodifiableList(infos);
- if (cache)
+ if (!(facesContext instanceof StartupFacesContextImpl))
{
applicationMap.put(SERVLET_REGISTRATIONS, infos);
}
@@ -140,7 +141,7 @@ public class FacesServletMappingUtils
}
public static ServletRegistrationInfo getFacesServletRegistration(FacesContext facesContext,
- ServletContext servletContext, boolean cache)
+ ServletContext servletContext)
{
Map<String, Object> applicationMap = facesContext.getExternalContext().getApplicationMap();
@@ -148,7 +149,7 @@ public class FacesServletMappingUtils
applicationMap.get(FACES_SERVLET_REGISTRATION);
if (facesServletRegistration == null)
{
- for (ServletRegistrationInfo info : getServletRegistrations(facesContext, servletContext, cache))
+ for (ServletRegistrationInfo info : getServletRegistrations(facesContext, servletContext))
{
if (info.isFacesServlet())
{
@@ -157,7 +158,7 @@ public class FacesServletMappingUtils
}
}
- if (facesServletRegistration != null && cache)
+ if (facesServletRegistration != null && !(facesContext instanceof StartupFacesContextImpl))
{
applicationMap.put(FACES_SERVLET_REGISTRATION, facesServletRegistration);
}
@@ -247,7 +248,7 @@ public class FacesServletMappingUtils
try
{
List<ServletRegistrationInfo> servletRegistrations =
- getServletRegistrations(facesContext, servletContext, true);
+ getServletRegistrations(facesContext, servletContext);
if (servletRegistrations != null)
{
FacesServletMapping facesExtensionMapping = null;
@@ -381,7 +382,7 @@ public class FacesServletMappingUtils
if (context instanceof ServletContext)
{
ServletRegistrationInfo facesServletRegistration =
- getFacesServletRegistration(facesContext, (ServletContext) context, true);
+ getFacesServletRegistration(facesContext, (ServletContext) context);
if (facesServletRegistration != null)
{
for (String mapping : facesServletRegistration.getMappings())
@@ -407,7 +408,7 @@ public class FacesServletMappingUtils
if (context instanceof ServletContext)
{
ServletRegistrationInfo facesServletRegistration =
- getFacesServletRegistration(facesContext, (ServletContext) context, true);
+ getFacesServletRegistration(facesContext, (ServletContext) context);
if (facesServletRegistration != null)
{
for (String mapping : facesServletRegistration.getMappings())
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerImpl.java b/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerImpl.java
index 1caf607..6470c86 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializerImpl.java
@@ -151,7 +151,7 @@ public class FacesInitializerImpl implements FacesInitializer
MyfacesConfig.INITIALIZE_ALWAYS_STANDALONE, false))
{
FacesServletMappingUtils.ServletRegistrationInfo facesServletRegistration =
- FacesServletMappingUtils.getFacesServletRegistration(facesContext, servletContext, false);
+ FacesServletMappingUtils.getFacesServletRegistration(facesContext, servletContext);
if (facesServletRegistration == null
|| facesServletRegistration.getMappings() == null
|| facesServletRegistration.getMappings().length == 0)
@@ -717,7 +717,7 @@ public class FacesInitializerImpl implements FacesInitializer
protected void initAutomaticExtensionlessMapping(FacesContext facesContext, ServletContext servletContext)
{
FacesServletMappingUtils.ServletRegistrationInfo facesServletRegistration =
- FacesServletMappingUtils.getFacesServletRegistration(facesContext, servletContext, false);
+ FacesServletMappingUtils.getFacesServletRegistration(facesContext, servletContext);
if (facesServletRegistration != null)
{
facesContext.getApplication().getViewHandler().getViews(facesContext, "/",
diff --git a/integration-tests/automaticExtensionlessMapping/pom.xml b/integration-tests/automaticExtensionlessMapping/pom.xml
new file mode 100644
index 0000000..5566125
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/pom.xml
@@ -0,0 +1,36 @@
+<?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>4.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.myfaces.core.integration-tests</groupId>
+ <artifactId>automaticExtensionlessMapping</artifactId>
+ <name>Apache MyFaces Core 4.0 - Integration Tests - automaticExtensionlessMapping</name>
+ <packaging>war</packaging>
+
+</project>
diff --git a/integration-tests/automaticExtensionlessMapping/src/main/java/org/apache/myfaces/core/integrationtests/IntegrationTestBean.java b/integration-tests/automaticExtensionlessMapping/src/main/java/org/apache/myfaces/core/integrationtests/IntegrationTestBean.java
new file mode 100644
index 0000000..7f04e41
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/src/main/java/org/apache/myfaces/core/integrationtests/IntegrationTestBean.java
@@ -0,0 +1,33 @@
+/*
+ * 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 jakarta.faces.annotation.FacesConfig.Version.JSF_2_3;
+
+import jakarta.enterprise.context.RequestScoped;
+import jakarta.faces.annotation.FacesConfig;
+import jakarta.inject.Named;
+
+@FacesConfig(version = JSF_2_3)
+@Named
+@RequestScoped
+public class IntegrationTestBean
+{
+
+}
diff --git a/integration-tests/automaticExtensionlessMapping/src/main/webapp/WEB-INF/beans.xml b/integration-tests/automaticExtensionlessMapping/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..9bcebd8
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/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/automaticExtensionlessMapping/src/main/webapp/WEB-INF/web.xml b/integration-tests/automaticExtensionlessMapping/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..c81ccc2
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,58 @@
+<?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>jakarta.faces.PROJECT_STAGE</param-name>
+ <param-value>Production</param-value>
+ </context-param>
+ <context-param>
+ <param-name>jakarta.faces.AUTOMATIC_EXTENSIONLESS_MAPPING</param-name>
+ <param-value>true</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.apache.myfaces.LOG_WEB_CONTEXT_PARAMS</param-name>
+ <param-value>false</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+ </listener>
+ <listener>
+ <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.xhtml</url-pattern>
+ </servlet-mapping>
+
+ <session-config>
+ <tracking-mode>COOKIE</tracking-mode>
+ </session-config>
+</web-app>
diff --git a/integration-tests/automaticExtensionlessMapping/src/main/webapp/bar.xhtml b/integration-tests/automaticExtensionlessMapping/src/main/webapp/bar.xhtml
new file mode 100644
index 0000000..ffb7315
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/src/main/webapp/bar.xhtml
@@ -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.
+-->
+<!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 id="form">
+ <h:link outcome="/foo.xhtml">Foo</h:link>
+ </h:form>
+ </h:body>
+</html>
+
diff --git a/integration-tests/automaticExtensionlessMapping/src/main/webapp/foo.xhtml b/integration-tests/automaticExtensionlessMapping/src/main/webapp/foo.xhtml
new file mode 100644
index 0000000..4d4f336
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/src/main/webapp/foo.xhtml
@@ -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.
+-->
+<!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 id="form">
+ <h:link outcome="/bar.xhtml">Bar</h:link>
+ </h:form>
+ </h:body>
+
+</html>
diff --git a/integration-tests/automaticExtensionlessMapping/src/test/java/org/apache/myfaces/core/integrationtests/IntegrationTest.java b/integration-tests/automaticExtensionlessMapping/src/test/java/org/apache/myfaces/core/integrationtests/IntegrationTest.java
new file mode 100644
index 0000000..96057b5
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/src/test/java/org/apache/myfaces/core/integrationtests/IntegrationTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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 foo()
+ {
+ webDriver.get(contextPath + "foo");
+
+ // check that URLs are rendered as exact mapping
+ Assert.assertTrue(webDriver.getPageSource().contains("/foo\""));
+
+ // check if served as non-exact-mapping
+ Assert.assertTrue(webDriver.getCurrentUrl().endsWith("/foo"));
+
+ Assert.assertTrue(webDriver.getPageSource().contains("/bar\""));
+ }
+
+ @Test
+ public void bar()
+ {
+ webDriver.get(contextPath + "bar");
+
+ // check that URLs are rendered as exact mapping
+ Assert.assertTrue(webDriver.getPageSource().contains("/bar\""));
+
+ // check if served as non-exact-mapping
+ Assert.assertTrue(webDriver.getCurrentUrl().endsWith("/bar"));
+
+ Assert.assertTrue(webDriver.getPageSource().contains("/foo\""));
+ }
+}
diff --git a/integration-tests/automaticExtensionlessMapping/src/test/resources/arquillian.xml b/integration-tests/automaticExtensionlessMapping/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..aafd361
--- /dev/null
+++ b/integration-tests/automaticExtensionlessMapping/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 9f38a70..6db2ff6 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -158,6 +158,7 @@
<module>autoLookupExpressionFactoryWithoutJSP</module>
<module>protectedViews</module>
<module>ajax</module>
+ <module>automaticExtensionlessMapping</module>
</modules>
<profiles>