Skip to content

Commit

Permalink
Fixes #3575 - Add CRaC support to Piranha Web Profile (#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Nov 26, 2023
1 parent c47f75c commit e937014
Showing 1 changed file with 45 additions and 0 deletions.
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 Web 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 @@ -162,6 +186,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 httpsServer = httpsFeature.getHttpsServer();
try {
HttpServer cracHttpServer = (HttpServer) Class
.forName("cloud.piranha.http.crac.CracHttpServer")
.getDeclaredConstructor(HttpServer.class)
.newInstance(httpsServer);
httpsServer = cracHttpServer;
} catch (ClassNotFoundException | IllegalAccessException
| IllegalArgumentException | InstantiationException
| NoSuchMethodException | SecurityException
| InvocationTargetException t) {
LOGGER.log(ERROR, "Unable to construct HTTP server", t);
}
httpsFeature.setHttpsServer(httpsServer);
}

httpsFeature.start();
}

Expand Down

0 comments on commit e937014

Please sign in to comment.