From cd51533453885033e5079a3c8e8ea71b9703b896 Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Thu, 26 Sep 2024 21:34:33 -0500 Subject: [PATCH] Fixes #4010 - Update Piranha Servlet - Create a Faces application guide (#4020) --- .../servlet/create_a_faces_application.md | 22 +-- test/micro/helloworld/pom.xml | 2 +- test/server/helloworld/pom.xml | 2 +- test/servlet/faces/pom.xml | 139 ++++++++++++++++++ .../faces/src/main/java/hello/HelloBean.java | 59 ++++++++ .../faces/src/main/webapp/WEB-INF/beans.xml | 7 + .../faces/src/main/webapp/WEB-INF/web.xml | 15 ++ .../faces/src/main/webapp/hellofaces.xhtml | 21 +++ .../faces/src/test/java/hello/HelloIT.java | 28 ++++ test/servlet/pom.xml | 1 + 10 files changed, 283 insertions(+), 13 deletions(-) create mode 100644 test/servlet/faces/pom.xml create mode 100644 test/servlet/faces/src/main/java/hello/HelloBean.java create mode 100644 test/servlet/faces/src/main/webapp/WEB-INF/beans.xml create mode 100644 test/servlet/faces/src/main/webapp/WEB-INF/web.xml create mode 100644 test/servlet/faces/src/main/webapp/hellofaces.xhtml create mode 100644 test/servlet/faces/src/test/java/hello/HelloIT.java diff --git a/docs/src/site/markdown/servlet/create_a_faces_application.md b/docs/src/site/markdown/servlet/create_a_faces_application.md index 18d5cc0386..a7146caff8 100644 --- a/docs/src/site/markdown/servlet/create_a_faces_application.md +++ b/docs/src/site/markdown/servlet/create_a_faces_application.md @@ -31,18 +31,18 @@ create the ```pom.xml``` file with the content as below. faces 24.10.0-SNAPSHOT war - Piranha Servlet - Jakarta Faces application + Create a Jakarta Faces application - 17 - 5.10.0-M1 - 3.11.0 - 3.0.0 - 3.3.2 - 4.0.2 + 21 + 5.11.0 + 3.13.0 + 3.5.0 + 3.4.0 + 4.0.7 servlet - 23.6.0 + 24.9.0 UTF-8 - 5.1.0.Final + 5.1.3.Final @@ -59,7 +59,7 @@ create the ```pom.xml``` file with the content as below. cloud.piranha.extension - piranha-extension-weld + piranha-extension-redhat-weld ${piranha.version} runtime @@ -86,7 +86,7 @@ create the ```pom.xml``` file with the content as below. faces - cloud.piranha.maven.plugins + cloud.piranha.maven piranha-maven-plugin ${piranha.version} diff --git a/test/micro/helloworld/pom.xml b/test/micro/helloworld/pom.xml index 9cbac30030..bb5cef2cbd 100644 --- a/test/micro/helloworld/pom.xml +++ b/test/micro/helloworld/pom.xml @@ -23,7 +23,7 @@ project 24.10.0-SNAPSHOT - cloud.piranha.guides.micro + cloud.piranha.test.micro helloworld 24.10.0-SNAPSHOT war diff --git a/test/server/helloworld/pom.xml b/test/server/helloworld/pom.xml index c39c5d1ec5..220940b7d1 100644 --- a/test/server/helloworld/pom.xml +++ b/test/server/helloworld/pom.xml @@ -20,7 +20,7 @@ project 24.10.0-SNAPSHOT - cloud.piranha.guides.server + cloud.piranha.test.server helloworld 24.10.0-SNAPSHOT war diff --git a/test/servlet/faces/pom.xml b/test/servlet/faces/pom.xml new file mode 100644 index 0000000000..ddd7acf39e --- /dev/null +++ b/test/servlet/faces/pom.xml @@ -0,0 +1,139 @@ + + + + 4.0.0 + + + cloud.piranha.test.servlet + project + 24.10.0-SNAPSHOT + + cloud.piranha.test.servlet + faces + 24.10.0-SNAPSHOT + war + Piranha - Test - Servlet - Jakarta Faces application + + 21 + 5.11.0 + 3.13.0 + 3.5.0 + 3.4.0 + 4.0.7 + servlet + 24.9.0 + UTF-8 + 5.1.3.Final + + + + org.glassfish + jakarta.faces + ${mojarra.version} + compile + + + org.jboss.weld.servlet + weld-servlet-shaded + ${weld.version} + compile + + + cloud.piranha.extension + piranha-extension-redhat-weld + ${piranha.version} + runtime + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + faces + + + cloud.piranha.maven + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + servlet + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + + integration-test + verify + + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + diff --git a/test/servlet/faces/src/main/java/hello/HelloBean.java b/test/servlet/faces/src/main/java/hello/HelloBean.java new file mode 100644 index 0000000000..cac1b4408b --- /dev/null +++ b/test/servlet/faces/src/main/java/hello/HelloBean.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package hello; + +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Named; + +@Named(value = "helloBean") +@RequestScoped +public class HelloBean { + + /** + * Stores the hello string. + */ + private String hello = "Hello from Jakarta Faces!"; + + /** + * Get the hello string. + * + * @return the hello string. + */ + public String getHello() { + return hello; + } + + /** + * Set the hello string. + * + * @param hello the hello string. + */ + public void setHello(String hello) { + this.hello = hello; + } +} diff --git a/test/servlet/faces/src/main/webapp/WEB-INF/beans.xml b/test/servlet/faces/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..05298c86da --- /dev/null +++ b/test/servlet/faces/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,7 @@ + + + + diff --git a/test/servlet/faces/src/main/webapp/WEB-INF/web.xml b/test/servlet/faces/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..8de5ccd77a --- /dev/null +++ b/test/servlet/faces/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,15 @@ + + + + + Faces Servlet + jakarta.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.xhtml + + diff --git a/test/servlet/faces/src/main/webapp/hellofaces.xhtml b/test/servlet/faces/src/main/webapp/hellofaces.xhtml new file mode 100644 index 0000000000..0dd605ba4a --- /dev/null +++ b/test/servlet/faces/src/main/webapp/hellofaces.xhtml @@ -0,0 +1,21 @@ + + + + + + + Jakarta Faces application + + + +
Jakarta Faces application
+ + +
+
+
+ diff --git a/test/servlet/faces/src/test/java/hello/HelloIT.java b/test/servlet/faces/src/test/java/hello/HelloIT.java new file mode 100644 index 0000000000..444e4a8054 --- /dev/null +++ b/test/servlet/faces/src/test/java/hello/HelloIT.java @@ -0,0 +1,28 @@ +package hello; + +import java.net.URI; +import java.net.http.HttpClient; +import static java.net.http.HttpClient.Redirect.ALWAYS; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; +import java.time.Duration; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +public class HelloIT { + + @Test + public void testHelloFacesXhtml() throws Exception { + HttpClient client = HttpClient + .newBuilder() + .connectTimeout(Duration.ofSeconds(60)) + .followRedirects(ALWAYS) + .build(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:8080/faces/hellofaces.xhtml")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello from Jakarta Faces!")); + } +} diff --git a/test/servlet/pom.xml b/test/servlet/pom.xml index b6e794e46f..f7b2258f08 100644 --- a/test/servlet/pom.xml +++ b/test/servlet/pom.xml @@ -16,6 +16,7 @@ Piranha - Test - Servlet - Project + faces hello