Skip to content

Commit

Permalink
Fixes #3573 - Add CRaC support to Piranha Core Profile (#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Nov 9, 2023
1 parent ada8145 commit caaf0d5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dist/coreprofile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cloud.piranha.http</groupId>
<artifactId>piranha-http-crac</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@
import cloud.piranha.feature.impl.DefaultFeatureManager;
import cloud.piranha.feature.logging.LoggingFeature;
import cloud.piranha.feature.webapp.WebAppFeature;
import cloud.piranha.http.api.HttpServer;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.System.Logger;
import static java.lang.System.Logger.Level.ERROR;
import static java.lang.System.Logger.Level.INFO;
import static java.lang.System.Logger.Level.WARNING;
import java.lang.reflect.InvocationTargetException;

/**
* The Piranha Core Profile runtime.
Expand Down Expand Up @@ -146,6 +149,27 @@ public void run() {
httpFeature.setPort(configuration.getInteger("httpPort"));
httpFeature.init();
httpFeature.getHttpServer().setHttpServerProcessor(webAppFeature.getHttpServerProcessor());

/*
* Enable Project CRaC.
*/
if (configuration.getBoolean("cracEnabled", false)) {
HttpServer httpServer = httpFeature.getHttpServer();
try {
HttpServer cracHttpServer = (HttpServer) Class
.forName("cloud.piranha.http.crac.CracHttpServer")
.getDeclaredConstructor(HttpServer.class)
.newInstance(httpServer);
httpServer = cracHttpServer;
} catch (ClassNotFoundException | IllegalAccessException
| IllegalArgumentException | InstantiationException
| NoSuchMethodException | SecurityException
| InvocationTargetException t) {
LOGGER.log(ERROR, "Unable to construct HTTP server", t);
}
httpFeature.setHttpServer(httpServer);
}

httpFeature.start();
}

Expand All @@ -163,6 +187,27 @@ public void run() {
httpsFeature.setPort(configuration.getInteger("httpsPort"));
httpsFeature.init();
httpsFeature.getHttpsServer().setHttpServerProcessor(webAppFeature.getHttpServerProcessor());

/*
* Enable Project CRaC.
*/
if (configuration.getBoolean("cracEnabled", false)) {
HttpServer httpServer = httpsFeature.getHttpsServer();
try {
HttpServer cracHttpServer = (HttpServer) Class
.forName("cloud.piranha.http.crac.CracHttpServer")
.getDeclaredConstructor(HttpServer.class)
.newInstance(httpServer);
httpServer = cracHttpServer;
} catch (ClassNotFoundException | IllegalAccessException
| IllegalArgumentException | InstantiationException
| NoSuchMethodException | SecurityException
| InvocationTargetException t) {
LOGGER.log(ERROR, "Unable to construct HTTP server", t);
}
httpsFeature.setHttpsServer(httpServer);
}

httpsFeature.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ public CoreProfilePiranhaBuilder contextPath(String contextPath) {
piranha.getConfiguration().setString("contextPath", contextPath);
return this;
}

/**
* Set the CRaC enabled flag.
*
* @param crac the CRaC enabled flag.
* @return the builder.
*/
public CoreProfilePiranhaBuilder crac(boolean crac) {
piranha.getConfiguration().setBoolean("cracEnabled", crac);
return this;
}

/**
* Set the exit on stop flag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ private CoreProfilePiranhaBuilder processArguments(String[] arguments) {
int httpsPort = 0;
if (arguments != null) {
for (int i = 0; i < arguments.length; i++) {
if (arguments[i].equals("--enable-crac")) {
builder = builder.crac(true);
}
if (arguments[i].equals("--extension-class")) {
builder = builder.extensionClass(arguments[i + 1]);
}
Expand Down Expand Up @@ -145,6 +148,7 @@ private static void showHelp() {
LOGGER.log(Level.INFO, "");
LOGGER.log(Level.INFO,
"""
--enable-crac - Enable Project CRaC support
--extension-class <className> - Set the extension to use
--context-path <string> - Set the Servlet context path
--help - Show this help
Expand Down

0 comments on commit caaf0d5

Please sign in to comment.