From 3519fe72346482370afc91070427b271e308f8d3 Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Sat, 26 Oct 2024 11:18:22 -0500 Subject: [PATCH] Fixes #4101 - Update Run a web application on Piranha Servlet with CRaC (#4139) --- bom/pom.xml | 5 + .../servlet/run_a_web_application_on_crac.md | 7 +- extension/weld/pom.xml | 1 - test/servlet/crac/pom.xml | 157 ++++++++++++++++++ .../crac/src/main/java/hello/HelloBean.java | 59 +++++++ .../crac/src/main/webapp/WEB-INF/beans.xml | 7 + .../crac/src/main/webapp/WEB-INF/web.xml | 15 ++ test/servlet/crac/src/main/webapp/hello.xhtml | 21 +++ .../crac/src/test/java/hello/HelloIT.java | 57 +++++++ test/servlet/pom.xml | 1 + 10 files changed, 324 insertions(+), 6 deletions(-) create mode 100644 test/servlet/crac/pom.xml create mode 100644 test/servlet/crac/src/main/java/hello/HelloBean.java create mode 100644 test/servlet/crac/src/main/webapp/WEB-INF/beans.xml create mode 100644 test/servlet/crac/src/main/webapp/WEB-INF/web.xml create mode 100644 test/servlet/crac/src/main/webapp/hello.xhtml create mode 100644 test/servlet/crac/src/test/java/hello/HelloIT.java diff --git a/bom/pom.xml b/bom/pom.xml index cff3b6331a..46f2e98ac5 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -82,6 +82,11 @@ jakarta.enterprise.cdi-api ${jakarta.enterprise.cdi-api.version} + + jakarta.enterprise + jakarta.enterprise.cdi-el-api + ${jakarta.enterprise.cdi-api.version} + jakarta.platform diff --git a/docs/src/site/markdown/servlet/run_a_web_application_on_crac.md b/docs/src/site/markdown/servlet/run_a_web_application_on_crac.md index e9df650cae..5e82543d9b 100644 --- a/docs/src/site/markdown/servlet/run_a_web_application_on_crac.md +++ b/docs/src/site/markdown/servlet/run_a_web_application_on_crac.md @@ -33,14 +33,14 @@ create the ```pom.xml``` file with the content as below. 4.0.0 cloud.piranha.guides.servlet crac - 24.11.0-SNAPSHOT + 1-SNAPSHOT war Run a web application on Piranha Servlet with CRaC 5.11.0-M1 4.1.1 - 24.4.0 + 24.11.0 6.0.0.Beta4 21 @@ -338,6 +338,3 @@ the right command line switch. ## References 1. [CRaC Project](https://wiki.openjdk.org/display/crac/Main) - -[Up](../) - diff --git a/extension/weld/pom.xml b/extension/weld/pom.xml index 4df37b588d..79cd8549b4 100644 --- a/extension/weld/pom.xml +++ b/extension/weld/pom.xml @@ -74,7 +74,6 @@ jakarta.enterprise jakarta.enterprise.cdi-el-api - 4.1.0-M1 runtime diff --git a/test/servlet/crac/pom.xml b/test/servlet/crac/pom.xml new file mode 100644 index 0000000000..845ff0c5f0 --- /dev/null +++ b/test/servlet/crac/pom.xml @@ -0,0 +1,157 @@ + + + + 4.0.0 + + cloud.piranha.test.servlet + project + 24.11.0-SNAPSHOT + + piranha-test-servlet-crac + war + Piranha - Test - Servlet - CRaC application + + + 5.11.0-M1 + 4.1.1 + ${project.version} + 6.0.0.Beta4 + + 21 + servlet + UTF-8 + + 3.6.0 + 3.13.0 + 3.2.5 + 3.4.0 + + + + + org.glassfish + jakarta.faces + ${mojarra.version} + compile + + + org.jboss.weld.servlet + weld-servlet-shaded + ${weld.version} + compile + + + + cloud.piranha.extension + piranha-extension-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 + + + + crac + + + cloud.piranha.maven + piranha-maven-plugin + ${piranha.version} + + + pre-integration-test + pre-integration-test + + start + + + + post-integration-test + post-integration-test + + stop + + + + + servlet + ${httpPort} + + + + 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 + + + + + 1 + + ${httpPort} + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + reserve-network-port + + reserve-network-port + + package + + + httpPort + + + + + + + + diff --git a/test/servlet/crac/src/main/java/hello/HelloBean.java b/test/servlet/crac/src/main/java/hello/HelloBean.java new file mode 100644 index 0000000000..51e1102152 --- /dev/null +++ b/test/servlet/crac/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 from CRaC!' message. + */ + private String hello = "Hello from CRaC!"; + + /** + * Get the message. + * + * @return the message. + */ + public String getHello() { + return hello; + } + + /** + * Set the message. + * + * @param hello the message. + */ + public void setHello(String hello) { + this.hello = hello; + } +} diff --git a/test/servlet/crac/src/main/webapp/WEB-INF/beans.xml b/test/servlet/crac/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..05298c86da --- /dev/null +++ b/test/servlet/crac/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,7 @@ + + + + diff --git a/test/servlet/crac/src/main/webapp/WEB-INF/web.xml b/test/servlet/crac/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..8de5ccd77a --- /dev/null +++ b/test/servlet/crac/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/crac/src/main/webapp/hello.xhtml b/test/servlet/crac/src/main/webapp/hello.xhtml new file mode 100644 index 0000000000..0dd605ba4a --- /dev/null +++ b/test/servlet/crac/src/main/webapp/hello.xhtml @@ -0,0 +1,21 @@ + + + + + + + Jakarta Faces application + + + +
Jakarta Faces application
+ + +
+
+
+ diff --git a/test/servlet/crac/src/test/java/hello/HelloIT.java b/test/servlet/crac/src/test/java/hello/HelloIT.java new file mode 100644 index 0000000000..e6d9a089a0 --- /dev/null +++ b/test/servlet/crac/src/test/java/hello/HelloIT.java @@ -0,0 +1,57 @@ +/* + * 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 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 { + + private String portNumber = System.getProperty("httpPort"); + + @Test + public void testHelloXhtml() throws Exception { + HttpClient client = HttpClient + .newBuilder() + .connectTimeout(Duration.ofSeconds(60)) + .followRedirects(ALWAYS) + .build(); + HttpRequest request = HttpRequest + .newBuilder(new URI("http://localhost:" + portNumber + "/crac/hello.xhtml")) + .build(); + HttpResponse response = client.send(request, BodyHandlers.ofString()); + assertTrue(response.body().contains("Hello from CRaC!")); + } +} diff --git a/test/servlet/pom.xml b/test/servlet/pom.xml index 075ce4e6c0..24689f29bc 100644 --- a/test/servlet/pom.xml +++ b/test/servlet/pom.xml @@ -31,6 +31,7 @@
+ crac faces hello helloworld