Skip to content

Commit

Permalink
Fixes piranhacloud#4101 - Update Run a web application on Piranha Ser…
Browse files Browse the repository at this point in the history
…vlet with CRaC (piranhacloud#4139)
  • Loading branch information
mnriem authored Oct 26, 2024
1 parent 5dc8f8f commit 3519fe7
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 6 deletions.
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>${jakarta.enterprise.cdi-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-el-api</artifactId>
<version>${jakarta.enterprise.cdi-api.version}</version>
</dependency>
<!-- Jakarta EE Core Profile -->
<dependency>
<groupId>jakarta.platform</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ create the ```pom.xml``` file with the content as below.
<modelVersion>4.0.0</modelVersion>
<groupId>cloud.piranha.guides.servlet</groupId>
<artifactId>crac</artifactId>
<version>24.11.0-SNAPSHOT</version>
<version>1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Run a web application on Piranha Servlet with CRaC</name>
<properties>
<!-- dependencies -->
<junit.version>5.11.0-M1</junit.version>
<mojarra.version>4.1.1</mojarra.version>
<piranha.version>24.4.0</piranha.version>
<piranha.version>24.11.0</piranha.version>
<weld.version>6.0.0.Beta4</weld.version>
<!-- other -->
<java.version>21</java.version>
Expand Down Expand Up @@ -338,6 +338,3 @@ the right command line switch.
## References

1. [CRaC Project](https://wiki.openjdk.org/display/crac/Main)

[Up](../)

1 change: 0 additions & 1 deletion extension/weld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-el-api</artifactId>
<version>4.1.0-M1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Expand Down
157 changes: 157 additions & 0 deletions test/servlet/crac/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cloud.piranha.test.servlet</groupId>
<artifactId>project</artifactId>
<version>24.11.0-SNAPSHOT</version>
</parent>
<artifactId>piranha-test-servlet-crac</artifactId>
<packaging>war</packaging>
<name>Piranha - Test - Servlet - CRaC application</name>
<properties>
<!-- dependencies -->
<junit.version>5.11.0-M1</junit.version>
<mojarra.version>4.1.1</mojarra.version>
<piranha.version>${project.version}</piranha.version>
<weld.version>6.0.0.Beta4</weld.version>
<!-- other -->
<java.version>21</java.version>
<piranha.distribution>servlet</piranha.distribution>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- plugins -->
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
</properties>
<dependencies>
<!-- compile -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
<version>${mojarra.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<version>${weld.version}</version>
<scope>compile</scope>
</dependency>
<!-- runtime -->
<dependency>
<groupId>cloud.piranha.extension</groupId>
<artifactId>piranha-extension-weld</artifactId>
<version>${piranha.version}</version>
<scope>runtime</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>crac</finalName>
<plugins>
<plugin>
<groupId>cloud.piranha.maven</groupId>
<artifactId>piranha-maven-plugin</artifactId>
<version>${piranha.version}</version>
<executions>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<distribution>servlet</distribution>
<httpPort>${httpPort}</httpPort>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<systemPropertyVariables>
<httpPort>${httpPort}</httpPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>package</phase>
<configuration>
<portNames>
<portName>httpPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
59 changes: 59 additions & 0 deletions test/servlet/crac/src/main/java/hello/HelloBean.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 7 additions & 0 deletions test/servlet/crac/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<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_2_0.xsd"
bean-discovery-mode="all">
</beans>
15 changes: 15 additions & 0 deletions test/servlet/crac/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<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>
</web-app>
21 changes: 21 additions & 0 deletions test/servlet/crac/src/main/webapp/hello.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="jakarta.faces.core"
xmlns:h="jakarta.faces.html"
xmlns:pt="jakarta.faces.passthrough">
<h:head>
<title>Jakarta Faces application</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<h:body>
<div>Jakarta Faces application</div>
<h:form>
<h:outputText value="#{helloBean.hello}"/>
<br/>
</h:form>
</h:body>
</html>
57 changes: 57 additions & 0 deletions test/servlet/crac/src/test/java/hello/HelloIT.java
Original file line number Diff line number Diff line change
@@ -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<String> response = client.send(request, BodyHandlers.ofString());
assertTrue(response.body().contains("Hello from CRaC!"));
}
}
1 change: 1 addition & 0 deletions test/servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</dependency>
</dependencies>
<modules>
<module>crac</module>
<module>faces</module>
<module>hello</module>
<module>helloworld</module>
Expand Down

0 comments on commit 3519fe7

Please sign in to comment.