diff --git a/core/impl/src/main/java/module-info.java b/core/impl/src/main/java/module-info.java index 78fa277201..a332e76ad2 100644 --- a/core/impl/src/main/java/module-info.java +++ b/core/impl/src/main/java/module-info.java @@ -37,5 +37,4 @@ opens cloud.piranha.core.impl; requires transitive cloud.piranha.core.api; requires transitive cloud.piranha.resource.impl; - requires java.base; } diff --git a/dist/coreprofile/pom.xml b/dist/coreprofile/pom.xml index 2a7616e745..b2d71f74a1 100644 --- a/dist/coreprofile/pom.xml +++ b/dist/coreprofile/pom.xml @@ -17,44 +17,14 @@ - cloud.piranha.extension - piranha-extension-coreprofile - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-exitonstop - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-http - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-https - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-logging + cloud.piranha + piranha-single ${project.version} compile - cloud.piranha.feature - piranha-feature-webapp - ${project.version} - compile - - - cloud.piranha.http - piranha-http-crac + cloud.piranha.extension + piranha-extension-coreprofile ${project.version} compile diff --git a/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranha.java b/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranha.java deleted file mode 100644 index af9bd3f0b0..0000000000 --- a/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranha.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * 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 cloud.piranha.dist.coreprofile; - -import cloud.piranha.core.api.Piranha; -import cloud.piranha.core.api.PiranhaConfiguration; -import cloud.piranha.core.api.WebApplicationExtension; -import cloud.piranha.core.impl.DefaultPiranhaConfiguration; -import cloud.piranha.extension.coreprofile.CoreProfileExtension; -import cloud.piranha.feature.api.FeatureManager; -import cloud.piranha.feature.exitonstop.ExitOnStopFeature; -import cloud.piranha.feature.http.HttpFeature; -import cloud.piranha.feature.https.HttpsFeature; -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. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class CoreProfilePiranha implements Piranha, Runnable { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(CoreProfilePiranha.class.getName()); - - /** - * Stores the configuration. - */ - private final PiranhaConfiguration configuration; - - /** - * Stores the feature manager. - */ - private final FeatureManager featureManager; - - /** - * Stores the HTTP feature. - */ - private HttpFeature httpFeature; - - /** - * Stores the HTTPS feature. - */ - private HttpsFeature httpsFeature; - - /** - * Stores the stop flag. - */ - private boolean stop = false; - - /** - * Stores the thread we use. - */ - private Thread thread; - - /** - * Stores the web app feature. - */ - private WebAppFeature webAppFeature; - - /** - * Constructor. - */ - public CoreProfilePiranha() { - configuration = new DefaultPiranhaConfiguration(); - configuration.setClass("extensionClass", CoreProfileExtension.class); - configuration.setBoolean("exitOnStop", false); - configuration.setInteger("httpPort", 8080); - configuration.setInteger("httpsPort", -1); - featureManager = new DefaultFeatureManager(); - } - - @Override - public PiranhaConfiguration getConfiguration() { - return configuration; - } - - /** - * Run method. - */ - @Override - public void run() { - long startTime = System.currentTimeMillis(); - - LoggingFeature loggingFeature = new LoggingFeature(); - featureManager.addFeature(loggingFeature); - loggingFeature.setLevel(configuration.getString("loggingLevel")); - loggingFeature.init(); - loggingFeature.start(); - - LOGGER.log(INFO, () -> "Starting Piranha"); - - webAppFeature = new WebAppFeature(); - featureManager.addFeature(webAppFeature); - webAppFeature.setContextPath(configuration.getString("contextPath")); - webAppFeature.setExtensionClass((Class) configuration.getClass("extensionClass")); - webAppFeature.setJpmsEnabled(configuration.getBoolean("jpmsEnabled", false)); - webAppFeature.setWarFile(configuration.getFile("warFile")); - webAppFeature.setWebAppDir(configuration.getFile("webAppDir")); - webAppFeature.init(); - webAppFeature.start(); - - /* - * Construct, initialize and start HTTP endpoint (if applicable). - */ - if (configuration.getInteger("httpPort") > 0) { - httpFeature = new HttpFeature(); - featureManager.addFeature(httpFeature); - httpFeature.setHttpServerClass(configuration.getString("httpServerClass")); - 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(); - } - - /** - * Construct, initialize and start the HTTPS endpoint (if applicable). - */ - if (configuration.getInteger("httpsPort") > 0) { - httpsFeature = new HttpsFeature(); - featureManager.addFeature(httpsFeature); - httpsFeature.setHttpsKeystoreFile(configuration.getString("httpsKeystoreFile")); - httpsFeature.setHttpsKeystorePassword(configuration.getString("httpsKeystorePassword")); - httpsFeature.setHttpsServerClass(configuration.getString("httpsServerClass")); - httpsFeature.setHttpsTruststoreFile(configuration.getString("httpsTruststoreFile")); - httpsFeature.setHttpsTruststorePassword(configuration.getString("httpsTruststorePassword")); - 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(); - } - - if (configuration.getBoolean("exitOnStop", false)) { - ExitOnStopFeature exitOnStopFeature = new ExitOnStopFeature(); - featureManager.addFeature(exitOnStopFeature); - exitOnStopFeature.init(); - exitOnStopFeature.start(); - } - - long finishTime = System.currentTimeMillis(); - LOGGER.log(INFO, "Started Piranha"); - LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime); - - if (getConfiguration().getLong("pid") != null) { - File pidFile = new File("tmp", "piranha.pid"); - if (!pidFile.getParentFile().exists() && !pidFile.getParentFile().mkdirs()) { - LOGGER.log(WARNING, "Unable to create tmp directory for PID file"); - } - try (PrintWriter writer = new PrintWriter(new FileWriter(pidFile))) { - writer.println(getConfiguration().getLong("pid")); - writer.flush(); - } catch (IOException ioe) { - LOGGER.log(WARNING, "Unable to write PID file", ioe); - } - } - - while (!stop) { - if (getConfiguration().getLong("pid") != null) { - File pidFile = new File("tmp", "piranha.pid"); - if (!pidFile.exists()) { - stop(); - } - } - try { - Thread.sleep(2000); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - } - } - } - - /** - * Start the server. - */ - public void start() { - thread = new Thread(this); - thread.start(); - } - - /** - * Stop the server. - */ - public void stop() { - stop = true; - thread = null; - featureManager.stop(); - } -} diff --git a/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaMain.java b/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaMain.java index 0be9b44a28..e29b12a677 100644 --- a/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaMain.java +++ b/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaMain.java @@ -27,6 +27,8 @@ */ package cloud.piranha.dist.coreprofile; +import cloud.piranha.extension.coreprofile.CoreProfileExtension; +import cloud.piranha.single.SinglePiranhaBuilder; import static java.lang.System.Logger.Level.WARNING; import java.lang.System.Logger; import java.lang.System.Logger.Level; @@ -49,7 +51,7 @@ public class CoreProfilePiranhaMain { * @param arguments the arguments. */ public static void main(String[] arguments) { - CoreProfilePiranhaBuilder builder = new CoreProfilePiranhaMain().processArguments(arguments); + SinglePiranhaBuilder builder = new CoreProfilePiranhaMain().processArguments(arguments); if (builder != null) { builder.build().start(); } else { @@ -62,9 +64,10 @@ public static void main(String[] arguments) { * * @param arguments the arguments. */ - private CoreProfilePiranhaBuilder processArguments(String[] arguments) { + private SinglePiranhaBuilder processArguments(String[] arguments) { - CoreProfilePiranhaBuilder builder = new CoreProfilePiranhaBuilder() + SinglePiranhaBuilder builder = new SinglePiranhaBuilder() + .extensionClass(CoreProfileExtension.class) .exitOnStop(true); int httpPort = 0; int httpsPort = 0; diff --git a/dist/coreprofile/src/main/java/module-info.java b/dist/coreprofile/src/main/java/module-info.java index d260fdf440..45f87de9c6 100644 --- a/dist/coreprofile/src/main/java/module-info.java +++ b/dist/coreprofile/src/main/java/module-info.java @@ -36,10 +36,6 @@ exports cloud.piranha.dist.coreprofile; opens cloud.piranha.dist.coreprofile; requires cloud.piranha.extension.coreprofile; - requires cloud.piranha.feature.exitonstop; - requires cloud.piranha.feature.http; - requires cloud.piranha.feature.https; - requires cloud.piranha.feature.logging; - requires cloud.piranha.feature.webapp; + requires cloud.piranha.single; requires java.logging; } diff --git a/dist/coreprofile/src/test/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaBuilderTest.java b/dist/coreprofile/src/test/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaBuilderTest.java deleted file mode 100644 index 6f20a71555..0000000000 --- a/dist/coreprofile/src/test/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaBuilderTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 cloud.piranha.dist.coreprofile; - -import cloud.piranha.extension.coreprofile.CoreProfileExtension; -import java.net.ConnectException; -import java.net.Socket; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the CoreProfilePiranhaBuilder class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class CoreProfilePiranhaBuilderTest { - - /** - * Test extensionClass method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testExtensionClass() throws Exception { - CoreProfilePiranha piranha = new CoreProfilePiranhaBuilder() - .extensionClass("cloud.piranha.extension.coreprofile.CoreProfileExtension") - .httpPort(8080) - .verbose(true) - .build(); - piranha.start(); - Thread.sleep(5000); - try ( Socket socket = new Socket("localhost", 8080)) { - assertNotNull(socket.getOutputStream()); - } catch (ConnectException e) { - } - piranha.stop(); - Thread.sleep(5000); - } - - /** - * Test extensionClass method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testExtensionClass2() throws Exception { - CoreProfilePiranha piranha = new CoreProfilePiranhaBuilder() - .extensionClass(CoreProfileExtension.class) - .httpPort(8081) - .verbose(true) - .build(); - piranha.start(); - Thread.sleep(5000); - try ( Socket socket = new Socket("localhost", 8081)) { - assertNotNull(socket.getOutputStream()); - } catch (ConnectException e) { - } - piranha.stop(); - Thread.sleep(5000); - } -} diff --git a/dist/microprofile/pom.xml b/dist/microprofile/pom.xml index 5bd42b3564..83bf7c0268 100644 --- a/dist/microprofile/pom.xml +++ b/dist/microprofile/pom.xml @@ -17,38 +17,14 @@ - cloud.piranha.extension - piranha-extension-microprofile - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-exitonstop - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-http + cloud.piranha + piranha-single ${project.version} compile - cloud.piranha.feature - piranha-feature-https - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-logging - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-webapp + cloud.piranha.extension + piranha-extension-microprofile ${project.version} compile diff --git a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranha.java b/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranha.java deleted file mode 100644 index a63f667412..0000000000 --- a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranha.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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 cloud.piranha.dist.microprofile; - -import cloud.piranha.core.api.Piranha; -import cloud.piranha.core.api.PiranhaConfiguration; -import cloud.piranha.core.api.WebApplicationExtension; -import cloud.piranha.core.impl.DefaultPiranhaConfiguration; -import cloud.piranha.extension.microprofile.MicroProfileExtension; -import cloud.piranha.feature.api.FeatureManager; -import cloud.piranha.feature.exitonstop.ExitOnStopFeature; -import cloud.piranha.feature.http.HttpFeature; -import cloud.piranha.feature.https.HttpsFeature; -import cloud.piranha.feature.impl.DefaultFeatureManager; -import cloud.piranha.feature.logging.LoggingFeature; -import cloud.piranha.feature.webapp.WebAppFeature; -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.INFO; -import static java.lang.System.Logger.Level.WARNING; - -/** - * The Piranha Micro runtime. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class MicroProfilePiranha implements Piranha, Runnable { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(MicroProfilePiranha.class.getName()); - - /** - * Stores the configuration. - */ - private final PiranhaConfiguration configuration; - - /** - * Stores the feature manager. - */ - private final FeatureManager featureManager; - - /** - * Stores the HTTP feature. - */ - private HttpFeature httpFeature; - - /** - * Stores the HTTPS feature. - */ - private HttpsFeature httpsFeature; - - /** - * Stores the stop flag. - */ - private boolean stop = false; - - /** - * Stores the thread we use. - */ - private Thread thread; - - /** - * Stores the web app feature. - */ - private WebAppFeature webAppFeature; - - /** - * Constructor. - */ - public MicroProfilePiranha() { - configuration = new DefaultPiranhaConfiguration(); - configuration.setBoolean("exitOnStop", false); - configuration.setClass("extensionClass", MicroProfileExtension.class); - configuration.setInteger("httpPort", 8080); - configuration.setInteger("httpsPort", -1); - configuration.setBoolean("jpmsEnabled", false); - featureManager = new DefaultFeatureManager(); - } - - @Override - public PiranhaConfiguration getConfiguration() { - return configuration; - } - - @Override - public void run() { - long startTime = System.currentTimeMillis(); - - LoggingFeature loggingFeature = new LoggingFeature(); - featureManager.addFeature(loggingFeature); - loggingFeature.setLevel(configuration.getString("loggingLevel")); - loggingFeature.init(); - loggingFeature.start(); - - LOGGER.log(INFO, () -> "Starting Piranha"); - - webAppFeature = new WebAppFeature(); - featureManager.addFeature(webAppFeature); - webAppFeature.setContextPath(configuration.getString("contextPath")); - webAppFeature.setExtensionClass((Class) configuration.getClass("extensionClass")); - webAppFeature.setJpmsEnabled(configuration.getBoolean("jpmsEnabled", false)); - webAppFeature.setWarFile(configuration.getFile("warFile")); - webAppFeature.setWebAppDir(configuration.getFile("webAppDir")); - webAppFeature.init(); - webAppFeature.start(); - - /* - * Construct, initialize and start HTTP endpoint (if applicable). - */ - if (configuration.getInteger("httpPort") > 0) { - httpFeature = new HttpFeature(); - httpFeature.setHttpServerClass(configuration.getString("httpServerClass")); - httpFeature.setPort(configuration.getInteger("httpPort")); - httpFeature.init(); - httpFeature.getHttpServer().setHttpServerProcessor(webAppFeature.getHttpServerProcessor()); - httpFeature.start(); - } - - /* - * Construct, initialize and start HTTP endpoint (if applicable). - */ - if (configuration.getInteger("httpsPort") > 0) { - httpsFeature = new HttpsFeature(); - httpsFeature.setHttpsKeystoreFile(configuration.getString("httpsKeystoreFile")); - httpsFeature.setHttpsKeystorePassword(configuration.getString("httpsKeystorePassword")); - httpsFeature.setHttpsServerClass(configuration.getString("httpsServerClass")); - httpsFeature.setHttpsTruststoreFile(configuration.getString("httpsTruststoreFile")); - httpsFeature.setHttpsTruststorePassword(configuration.getString("httpsTruststorePassword")); - httpsFeature.setPort(configuration.getInteger("httpsPort")); - httpsFeature.init(); - httpsFeature.getHttpsServer().setHttpServerProcessor(webAppFeature.getHttpServerProcessor()); - httpsFeature.start(); - } - - if (configuration.getBoolean("exitOnStop", false)) { - ExitOnStopFeature exitOnStopFeature = new ExitOnStopFeature(); - featureManager.addFeature(exitOnStopFeature); - exitOnStopFeature.init(); - exitOnStopFeature.start(); - } - - long finishTime = System.currentTimeMillis(); - LOGGER.log(INFO, "Started Piranha"); - LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime); - - if (configuration.getLong("pid") != null) { - File pidFile = new File("tmp", "piranha.pid"); - if (!pidFile.getParentFile().exists() && !pidFile.getParentFile().mkdirs()) { - LOGGER.log(WARNING, "Unable to create tmp directory for PID file"); - } - try (PrintWriter writer = new PrintWriter(new FileWriter(pidFile))) { - writer.println(configuration.getLong("pid")); - writer.flush(); - } catch (IOException ioe) { - LOGGER.log(WARNING, "Unable to write PID file", ioe); - } - } - - while (!stop) { - if (configuration.getLong("pid") != null) { - File pidFile = new File("tmp", "piranha.pid"); - if (!pidFile.exists()) { - stop(); - } - } - try { - Thread.sleep(2000); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - } - } - } - - /** - * Start the server. - */ - public void start() { - thread = new Thread(this); - thread.start(); - } - - /** - * Stop the server. - */ - public void stop() { - stop = true; - thread = null; - featureManager.stop(); - } -} diff --git a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaBuilder.java b/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaBuilder.java deleted file mode 100644 index 518cd35855..0000000000 --- a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaBuilder.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * 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 cloud.piranha.dist.microprofile; - -import cloud.piranha.core.api.PiranhaBuilder; -import cloud.piranha.core.api.PiranhaConfiguration; -import cloud.piranha.core.api.WebApplicationExtension; -import java.io.File; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; -import static java.lang.System.Logger.Level.WARNING; - -/** - * The Builder for Piranha Web Profile. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class MicroProfilePiranhaBuilder implements PiranhaBuilder { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(MicroProfilePiranhaBuilder.class.getName()); - - /** - * Stores the Micro Profile Piranha instance. - */ - private final MicroProfilePiranha piranha = new MicroProfilePiranha(); - - /** - * Stores the verbose flag. - */ - private boolean verbose = false; - - /** - * Build the Piranha instance. - * - * @return the Piranha instance. - */ - public MicroProfilePiranha build() { - if (verbose) { - showArguments(); - } - return piranha; - } - - /** - * Set the context path. - * - * @param contextPath the context path. - * @return the builder. - */ - public MicroProfilePiranhaBuilder contextPath(String contextPath) { - piranha.getConfiguration().setString("contextPath", contextPath); - return this; - } - - /** - * Set the exit on stop flag. - * - * @param exitOnStop the exit on stop flag. - * @return the builder. - */ - public MicroProfilePiranhaBuilder exitOnStop(boolean exitOnStop) { - piranha.getConfiguration().setBoolean("exitOnStop", exitOnStop); - return this; - } - - /** - * Set the extension class. - * - * @param extensionClass the extension class. - * @return the builder. - */ - public MicroProfilePiranhaBuilder extensionClass( - Class extensionClass) { - piranha.getConfiguration().setClass("extensionClass", extensionClass); - return this; - } - - /** - * Set the extension class. - * - * @param extensionClassName the default extension class name. - * @return the builder. - */ - public MicroProfilePiranhaBuilder extensionClass(String extensionClassName) { - try { - extensionClass(Class.forName(extensionClassName) - .asSubclass(WebApplicationExtension.class)); - } catch (ClassNotFoundException cnfe) { - LOGGER.log(WARNING, "Unable to load extension class", cnfe); - } - return this; - } - - /** - * Set the HTTP server port. - * - * @param httpPort the HTTP server port. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpPort(int httpPort) { - piranha.getConfiguration().setInteger("httpPort", httpPort); - return this; - } - - /** - * Set the HTTP server class. - * - * @param httpServerClass the HTTP server class. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpServerClass(String httpServerClass) { - piranha.getConfiguration().setString("httpServerClass", httpServerClass); - return this; - } - - /** - * Set the HTTPS keystore file. - * - * @param httpsKeystoreFile the HTTPS keystore file. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpsKeystoreFile(String httpsKeystoreFile) { - piranha.getConfiguration().setString("httpsKeystoreFile", httpsKeystoreFile); - return this; - } - - /** - * Set the HTTPS keystore password. - * - * @param httpsKeystorePassword the HTTPS keystore password. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpsKeystorePassword(String httpsKeystorePassword) { - piranha.getConfiguration().setString("httpsKeystorePassword", httpsKeystorePassword); - return this; - } - - /** - * Set the HTTPS server port. - * - * @param httpsPort the HTTPS server port. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpsPort(int httpsPort) { - piranha.getConfiguration().setInteger("httpsPort", httpsPort); - return this; - } - - /** - * Set the HTTPS server class. - * - * @param httpsServerClass the HTTPS server class. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpsServerClass(String httpsServerClass) { - piranha.getConfiguration().setString("httpsServerClass", httpsServerClass); - return this; - } - - /** - * Set the HTTPS truststore file. - * - * @param httpsTruststoreFile the HTTPS truststore file. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpsTruststoreFile(String httpsTruststoreFile) { - piranha.getConfiguration().setString("httpsTruststoreFile", httpsTruststoreFile); - return this; - } - - /** - * Set the HTTPS truststore password. - * - * @param httpsTruststorePassword the HTTPS truststore password. - * @return the builder. - */ - public MicroProfilePiranhaBuilder httpsTruststorePassword(String httpsTruststorePassword) { - piranha.getConfiguration().setString("httpsTruststorePassword", httpsTruststorePassword); - return this; - } - - /** - * Enable/disable JPMS. - * - * @param jpms the JPMS flag. - * @return the builder. - */ - public MicroProfilePiranhaBuilder jpms(boolean jpms) { - piranha.getConfiguration().setBoolean("jpmsEnabled", jpms); - return this; - } - - /** - * Set the logging level. - * - * @param loggingLevel the logging level. - * @return the builder. - */ - public MicroProfilePiranhaBuilder loggingLevel(String loggingLevel) { - piranha.getConfiguration().setString("loggingLevel", loggingLevel); - return this; - } - - /** - * Show the arguments used. - */ - private void showArguments() { - PiranhaConfiguration configuration = piranha.getConfiguration(); - - LOGGER.log(Level.INFO, - """ - - PIRANHA - - Arguments - ========= - - Context path : %s - Extension class : %s - Exit on stop : %s - HTTP port : %s - HTTP server class : %s - HTTPS keystore file : %s - HTTPS keystore password : **** - HTTPS port : %s - HTTPS server class : %s - HTTPS truststore file : %s - HTTPS truststore password : **** - JPMS enabled : %s - Logging Level : %s - PID : %s - WAR filename : %s - Web application dir : %s - - """.formatted( - configuration.getString("contextPath"), - configuration.getClass("extensionClass"), - configuration.getBoolean("exitOnStop", false), - configuration.getInteger("httpPort"), - configuration.getString("httpServerClass"), - configuration.getString("httpsKeystoreFile"), - configuration.getInteger("httpsPort"), - configuration.getString("httpsServerClass"), - configuration.getString("httpsTruststoreFile"), - configuration.getBoolean("jpms", false), - configuration.getString("loggingLevel"), - configuration.getLong("pid"), - configuration.getFile("warFile"), - configuration.getFile("webAppDir") - ) - ); - } - - /** - * Set the verbose flag. - * - * @param verbose the verbose flag. - * @return the builder. - */ - public MicroProfilePiranhaBuilder verbose(boolean verbose) { - this.verbose = verbose; - return this; - } - - /** - * Set the WAR file. - * - * @param warFile the WAR file. - * @return the builder. - */ - public MicroProfilePiranhaBuilder warFile(String warFile) { - if (warFile != null) { - piranha.getConfiguration().setFile("warFile", new File(warFile)); - } - return this; - } - - /** - * Set the web application directory. - * - * @param webAppDir the web application directory. - * @return the builder. - */ - public MicroProfilePiranhaBuilder webAppDir(String webAppDir) { - if (webAppDir != null) { - piranha.getConfiguration().setFile("webAppDir", new File(webAppDir)); - } - return this; - } - - /** - * Set the PID. - * - * @param pid the PID. - * @return the builder. - */ - public MicroProfilePiranhaBuilder pid(Long pid) { - piranha.getConfiguration().setLong("pid", pid); - return this; - } -} diff --git a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java b/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java index 5a7acbfb00..2cb82c5798 100644 --- a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java +++ b/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java @@ -28,6 +28,7 @@ package cloud.piranha.dist.microprofile; import cloud.piranha.extension.microprofile.MicroProfileExtension; +import cloud.piranha.single.SinglePiranhaBuilder; import static java.lang.System.Logger.Level.WARNING; import java.lang.System.Logger; import java.lang.System.Logger.Level; @@ -50,7 +51,7 @@ public class MicroProfilePiranhaMain { * @param arguments the arguments. */ public static void main(String[] arguments) { - MicroProfilePiranhaBuilder builder = new MicroProfilePiranhaMain().processArguments(arguments); + SinglePiranhaBuilder builder = new MicroProfilePiranhaMain().processArguments(arguments); if (builder != null) { builder.build().start(); } else { @@ -63,9 +64,9 @@ public static void main(String[] arguments) { * * @param arguments the arguments. */ - private MicroProfilePiranhaBuilder processArguments(String[] arguments) { + private SinglePiranhaBuilder processArguments(String[] arguments) { - MicroProfilePiranhaBuilder builder = new MicroProfilePiranhaBuilder() + SinglePiranhaBuilder builder = new SinglePiranhaBuilder() .extensionClass(MicroProfileExtension.class) .exitOnStop(true); int httpPort = 0; diff --git a/dist/microprofile/src/main/java/module-info.java b/dist/microprofile/src/main/java/module-info.java index 1a654b2712..9e983c3e18 100644 --- a/dist/microprofile/src/main/java/module-info.java +++ b/dist/microprofile/src/main/java/module-info.java @@ -36,10 +36,6 @@ exports cloud.piranha.dist.microprofile; opens cloud.piranha.dist.microprofile; requires cloud.piranha.extension.microprofile; - requires cloud.piranha.feature.exitonstop; - requires cloud.piranha.feature.http; - requires cloud.piranha.feature.https; - requires cloud.piranha.feature.logging; - requires cloud.piranha.feature.webapp; + requires cloud.piranha.single; requires java.logging; } diff --git a/dist/microprofile/src/test/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaBuilderTest.java b/dist/microprofile/src/test/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaBuilderTest.java deleted file mode 100644 index cfd1701814..0000000000 --- a/dist/microprofile/src/test/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaBuilderTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 cloud.piranha.dist.microprofile; - -import cloud.piranha.extension.microprofile.MicroProfileExtension; -import java.net.ConnectException; -import java.net.Socket; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.jupiter.api.Test; - -/** - * The JUnit tests for the MicroProfilePiranhaBuilder class. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -class MicroProfilePiranhaBuilderTest { - - /** - * Test extensionClass method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testExtensionClass() throws Exception { - MicroProfilePiranha piranha = new MicroProfilePiranhaBuilder() - .extensionClass("cloud.piranha.extension.microprofile.MicroProfileExtension") - .httpPort(8080) - .verbose(true) - .build(); - piranha.start(); - Thread.sleep(5000); - try ( Socket socket = new Socket("localhost", 8080)) { - assertNotNull(socket.getOutputStream()); - } catch (ConnectException e) { - } - piranha.stop(); - Thread.sleep(5000); - } - - /** - * Test extensionClass method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testExtensionClass2() throws Exception { - MicroProfilePiranha piranha = new MicroProfilePiranhaBuilder() - .extensionClass(MicroProfileExtension.class) - .httpPort(8081) - .verbose(true) - .build(); - piranha.start(); - Thread.sleep(5000); - try ( Socket socket = new Socket("localhost", 8081)) { - assertNotNull(socket.getOutputStream()); - } catch (ConnectException e) { - } - piranha.stop(); - Thread.sleep(5000); - } -} diff --git a/dist/servlet/pom.xml b/dist/servlet/pom.xml index 75af316632..f389c1b42d 100644 --- a/dist/servlet/pom.xml +++ b/dist/servlet/pom.xml @@ -18,44 +18,14 @@ - cloud.piranha.extension - piranha-extension-servlet - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-exitonstop - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-http - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-https - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-logging + cloud.piranha + piranha-single ${project.version} compile - cloud.piranha.feature - piranha-feature-webapp - ${project.version} - compile - - - cloud.piranha.http - piranha-http-crac + cloud.piranha.extension + piranha-extension-servlet ${project.version} compile diff --git a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranha.java b/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranha.java deleted file mode 100644 index 013902f09f..0000000000 --- a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranha.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * 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 cloud.piranha.dist.servlet; - -import cloud.piranha.core.api.Piranha; -import cloud.piranha.core.api.PiranhaConfiguration; -import cloud.piranha.core.api.WebApplicationExtension; -import cloud.piranha.core.impl.DefaultPiranhaConfiguration; -import cloud.piranha.extension.servlet.ServletExtension; -import cloud.piranha.feature.api.FeatureManager; -import cloud.piranha.feature.exitonstop.ExitOnStopFeature; -import cloud.piranha.feature.http.HttpFeature; -import cloud.piranha.feature.https.HttpsFeature; -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 Servlet runtime. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class ServletPiranha implements Piranha, Runnable { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(ServletPiranha.class.getName()); - - /** - * Stores the configuration. - */ - private final PiranhaConfiguration configuration; - - /** - * Stores the feature manager. - */ - private final FeatureManager featureManager; - - /** - * Stores the HTTP feature. - */ - private HttpFeature httpFeature; - - /** - * Stores the HTTP feature. - */ - private HttpsFeature httpsFeature; - - /** - * Stores the stop flag. - */ - private boolean stop = false; - - /** - * Stores the thread we use. - */ - private Thread thread; - - /** - * Stores the web application feature. - */ - private WebAppFeature webAppFeature; - - /** - * Constructor. - */ - public ServletPiranha() { - configuration = new DefaultPiranhaConfiguration(); - configuration.setBoolean("cracEnabled", false); - configuration.setBoolean("exitOnStop", false); - configuration.setClass("extensionClass", ServletExtension.class); - configuration.setInteger("httpPort", 8080); - configuration.setInteger("httpsPort", -1); - configuration.setBoolean("jpmsEnabled", false); - featureManager = new DefaultFeatureManager(); - } - - @Override - public PiranhaConfiguration getConfiguration() { - return configuration; - } - - @Override - public void run() { - long startTime = System.currentTimeMillis(); - - LoggingFeature loggingFeature = new LoggingFeature(); - featureManager.addFeature(loggingFeature); - loggingFeature.setLevel(configuration.getString("loggingLevel")); - loggingFeature.init(); - loggingFeature.start(); - - LOGGER.log(INFO, () -> "Starting Piranha"); - - webAppFeature = new WebAppFeature(); - featureManager.addFeature(webAppFeature); - webAppFeature.setContextPath(configuration.getString("contextPath")); - webAppFeature.setExtensionClass((Class) configuration.getClass("extensionClass")); - webAppFeature.setJpmsEnabled(configuration.getBoolean("jpmsEnabled", false)); - webAppFeature.setWarFile(configuration.getFile("warFile")); - webAppFeature.setWebAppDir(configuration.getFile("webAppDir")); - webAppFeature.init(); - webAppFeature.start(); - - /* - * Construct, initialize and start HTTP endpoint (if applicable). - */ - if (configuration.getInteger("httpPort") > 0) { - httpFeature = new HttpFeature(); - httpFeature.setHttpServerClass(configuration.getString("httpServerClass")); - 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(); - } - - /* - * Construct, initialize and start HTTP endpoint (if applicable). - */ - if (configuration.getInteger("httpsPort") > 0) { - httpsFeature = new HttpsFeature(); - httpsFeature.setHttpsKeystoreFile(configuration.getString("httpsKeystoreFile")); - httpsFeature.setHttpsKeystorePassword(configuration.getString("httpsKeystorePassword")); - httpsFeature.setHttpsServerClass(configuration.getString("httpsServerClass")); - httpsFeature.setHttpsTruststoreFile(configuration.getString("httpsTruststoreFile")); - httpsFeature.setHttpsTruststorePassword(configuration.getString("httpsTruststorePassword")); - 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(); - } - - if (configuration.getBoolean("exitOnStop", false)) { - ExitOnStopFeature exitOnStopFeature = new ExitOnStopFeature(); - featureManager.addFeature(exitOnStopFeature); - } - - long finishTime = System.currentTimeMillis(); - LOGGER.log(INFO, "Started Piranha"); - LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime); - - if (configuration.getLong("pid") != null) { - File pidFile = new File("tmp", "piranha.pid"); - if (!pidFile.getParentFile().exists() && !pidFile.getParentFile().mkdirs()) { - LOGGER.log(WARNING, "Unable to create tmp directory for PID file"); - } - try (PrintWriter writer = new PrintWriter(new FileWriter(pidFile))) { - writer.println(configuration.getLong("pid")); - writer.flush(); - } catch (IOException ioe) { - LOGGER.log(WARNING, "Unable to write PID file", ioe); - } - } - - while (!stop) { - if (configuration.getLong("pid") != null) { - File pidFile = new File("tmp", "piranha.pid"); - if (!pidFile.exists()) { - stop(); - } - } - try { - Thread.sleep(2000); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - } - } - } - - /** - * Start the server. - */ - public void start() { - thread = new Thread(this); - thread.start(); - } - - /** - * Stop the server. - */ - public void stop() { - stop = true; - thread = null; - featureManager.stop(); - } -} diff --git a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaBuilder.java b/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaBuilder.java deleted file mode 100644 index cf5b6879e5..0000000000 --- a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaBuilder.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * 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 cloud.piranha.dist.servlet; - -import cloud.piranha.core.api.PiranhaBuilder; -import cloud.piranha.core.api.PiranhaConfiguration; -import cloud.piranha.core.api.WebApplicationExtension; -import java.io.File; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; - -import static java.lang.System.Logger.Level.WARNING; - -/** - * The Builder for Piranha Servlet. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class ServletPiranhaBuilder implements PiranhaBuilder { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(ServletPiranhaBuilder.class.getName()); - - /** - * Stores the Piranha Servlet instance. - */ - private final ServletPiranha piranha = new ServletPiranha(); - - /** - * Stores the verbose flag. - */ - private boolean verbose = false; - - /** - * Build the Piranha instance. - * - * @return the Piranha instance. - */ - public ServletPiranha build() { - if (verbose) { - showArguments(); - } - return piranha; - } - - /** - * Set the context path. - * - * @param contextPath the context path. - * @return the builder. - */ - public ServletPiranhaBuilder 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 ServletPiranhaBuilder crac(boolean crac) { - piranha.getConfiguration().setBoolean("cracEnabled", crac); - return this; - } - - /** - * Set the exit on stop flag. - * - * @param exitOnStop the exit on stop flag. - * @return the builder. - */ - public ServletPiranhaBuilder exitOnStop(boolean exitOnStop) { - piranha.getConfiguration().setBoolean("exitOnStop", exitOnStop); - return this; - } - - /** - * Set the extension class. - * - * @param extensionClass the extension class. - * @return the builder. - */ - public ServletPiranhaBuilder extensionClass( - Class extensionClass) { - piranha.getConfiguration().setClass("extensionClass", extensionClass); - return this; - } - - /** - * Set the extension class. - * - * @param extensionClassName the default extension class name. - * @return the builder. - */ - public ServletPiranhaBuilder extensionClass(String extensionClassName) { - try { - extensionClass(Class.forName(extensionClassName) - .asSubclass(WebApplicationExtension.class)); - } catch (ClassNotFoundException cnfe) { - LOGGER.log(WARNING, "Unable to load extension class", cnfe); - } - return this; - } - - /** - * Set the HTTP server port. - * - * @param httpPort the HTTP server port. - * @return the builder. - */ - public ServletPiranhaBuilder httpPort(int httpPort) { - piranha.getConfiguration().setInteger("httpPort", httpPort); - return this; - } - - /** - * Set the HTTP server class. - * - * @param httpServerClass the HTTP server class. - * @return the builder. - */ - public ServletPiranhaBuilder httpServerClass(String httpServerClass) { - piranha.getConfiguration().setString("httpServerClass", httpServerClass); - return this; - } - - /** - * Set the HTTPS keystore file. - * - * @param httpsKeystoreFile the HTTPS keystore file. - * @return the builder. - */ - public ServletPiranhaBuilder httpsKeystoreFile(String httpsKeystoreFile) { - piranha.getConfiguration().setString("httpsKeystoreFile", httpsKeystoreFile); - return this; - } - - /** - * Set the HTTPS keystore password. - * - * @param httpsKeystorePassword the HTTPS keystore password. - * @return the builder. - */ - public ServletPiranhaBuilder httpsKeystorePassword(String httpsKeystorePassword) { - piranha.getConfiguration().setString("httpsKeystorePassword", httpsKeystorePassword); - return this; - } - - /** - * Set the HTTPS server port. - * - * @param httpsPort the HTTPS server port. - * @return the builder. - */ - public ServletPiranhaBuilder httpsPort(int httpsPort) { - piranha.getConfiguration().setInteger("httpsPort", httpsPort); - return this; - } - - /** - * Set the HTTPS server class. - * - * @param httpsServerClass the HTTPS server class. - * @return the builder. - */ - public ServletPiranhaBuilder httpsServerClass(String httpsServerClass) { - piranha.getConfiguration().setString("httpsServerClass", httpsServerClass); - return this; - } - - /** - * Set the HTTPS truststore file. - * - * @param httpsTruststoreFile the HTTPS truststore file. - * @return the builder. - */ - public ServletPiranhaBuilder httpsTruststoreFile(String httpsTruststoreFile) { - piranha.getConfiguration().setString("httpsTruststoreFile", httpsTruststoreFile); - return this; - } - - /** - * Set the HTTPS truststore password. - * - * @param httpsTruststorePassword the HTTPS truststore password. - * @return the builder. - */ - public ServletPiranhaBuilder httpsTruststorePassword(String httpsTruststorePassword) { - piranha.getConfiguration().setString("httpsTruststorePassword", httpsTruststorePassword); - return this; - } - - /** - * Enable/disable JPMS. - * - * @param jpms the JPMS flag. - * @return the builder. - */ - public ServletPiranhaBuilder jpms(boolean jpms) { - piranha.getConfiguration().setBoolean("jpmsEnabled", jpms); - return this; - } - - /** - * Set the logging level. - * - * @param loggingLevel the logging level. - * @return the builder. - */ - public ServletPiranhaBuilder loggingLevel(String loggingLevel) { - piranha.getConfiguration().setString("loggingLevel", loggingLevel); - return this; - } - - /** - * Set the PID. - * - * @param pid the PID. - * @return the builder. - */ - public ServletPiranhaBuilder pid(Long pid) { - piranha.getConfiguration().setLong("pid", pid); - return this; - } - - /** - * Show the arguments used. - */ - private void showArguments() { - PiranhaConfiguration configuration = piranha.getConfiguration(); - - LOGGER.log(Level.INFO, - """ - - PIRANHA - - Arguments - ========= - - Context path : %s - Extension class : %s - Exit on stop : %s - HTTP port : %s - HTTP server class : %s - HTTPS keystore file : %s - HTTPS keystore password : **** - HTTPS port : %s - HTTPS server class : %s - HTTPS truststore file : %s - HTTPS truststore password : **** - JPMS enabled : %s - Logging level : %s - PID : %s - WAR filename : %s - Web application dir : %s - - """.formatted( - configuration.getString("contextPath"), - configuration.getClass("extensionClass"), - configuration.getBoolean("exitOnStop", false), - configuration.getInteger("httpPort"), - configuration.getString("httpServerClass"), - configuration.getString("httpsKeystoreFile"), - configuration.getInteger("httpsPort"), - configuration.getString("httpsServerClass"), - configuration.getString("httpsTruststoreFile"), - configuration.getBoolean("jpms", false), - configuration.getString("loggingLevel"), - configuration.getLong("pid"), - configuration.getFile("warFile"), - configuration.getFile("webAppDir") - ) - ); - } - - /** - * Set the verbose flag. - * - * @param verbose the verbose flag. - * @return the builder. - */ - public ServletPiranhaBuilder verbose(boolean verbose) { - this.verbose = verbose; - return this; - } - - /** - * Set the WAR file. - * - * @param warFile the WAR file. - * @return the builder. - */ - public ServletPiranhaBuilder warFile(String warFile) { - if (warFile != null) { - piranha.getConfiguration().setFile("warFile", new File(warFile)); - } - return this; - } - - /** - * Set the web application directory. - * - * @param webAppDir the web application directory. - * @return the builder. - */ - public ServletPiranhaBuilder webAppDir(String webAppDir) { - if (webAppDir != null) { - piranha.getConfiguration().setFile("webAppDir", new File(webAppDir)); - } - return this; - } -} diff --git a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java b/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java index 469d742e1a..e9e1a0701d 100644 --- a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java +++ b/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java @@ -28,6 +28,7 @@ package cloud.piranha.dist.servlet; import cloud.piranha.extension.servlet.ServletExtension; +import cloud.piranha.single.SinglePiranhaBuilder; import static java.lang.System.Logger.Level.WARNING; import java.lang.System.Logger; import java.lang.System.Logger.Level; @@ -50,7 +51,7 @@ public class ServletPiranhaMain { * @param arguments the arguments. */ public static void main(String[] arguments) { - ServletPiranhaBuilder builder = new ServletPiranhaMain().processArguments(arguments); + SinglePiranhaBuilder builder = new ServletPiranhaMain().processArguments(arguments); if (builder != null) { builder.build().start(); } else { @@ -63,9 +64,9 @@ public static void main(String[] arguments) { * * @param arguments the arguments. */ - private ServletPiranhaBuilder processArguments(String[] arguments) { + private SinglePiranhaBuilder processArguments(String[] arguments) { - ServletPiranhaBuilder builder = new ServletPiranhaBuilder() + SinglePiranhaBuilder builder = new SinglePiranhaBuilder() .extensionClass(ServletExtension.class) .exitOnStop(true); int httpPort = 0; diff --git a/dist/servlet/src/main/java/module-info.java b/dist/servlet/src/main/java/module-info.java index 3af27870e9..9751fca849 100644 --- a/dist/servlet/src/main/java/module-info.java +++ b/dist/servlet/src/main/java/module-info.java @@ -36,12 +36,6 @@ exports cloud.piranha.dist.servlet; opens cloud.piranha.dist.servlet; requires cloud.piranha.extension.servlet; - requires cloud.piranha.feature.exitonstop; - requires cloud.piranha.feature.http; - requires cloud.piranha.feature.https; - requires cloud.piranha.feature.logging; - requires cloud.piranha.feature.webapp; - requires cloud.piranha.http.crac; - requires cloud.piranha.http.webapp; + requires cloud.piranha.single; requires java.logging; } diff --git a/dist/webprofile/pom.xml b/dist/webprofile/pom.xml index 75e3dabf48..0053b70e2c 100644 --- a/dist/webprofile/pom.xml +++ b/dist/webprofile/pom.xml @@ -17,38 +17,14 @@ - cloud.piranha.extension - piranha-extension-webprofile - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-exitonstop - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-http + cloud.piranha + piranha-single ${project.version} compile - cloud.piranha.feature - piranha-feature-https - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-logging - ${project.version} - compile - - - cloud.piranha.feature - piranha-feature-webapp + cloud.piranha.extension + piranha-extension-webprofile ${project.version} compile diff --git a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaBuilder.java b/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaBuilder.java deleted file mode 100644 index 06f477e8f2..0000000000 --- a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaBuilder.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * 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 cloud.piranha.dist.webprofile; - -import cloud.piranha.core.api.PiranhaBuilder; -import cloud.piranha.core.api.PiranhaConfiguration; -import cloud.piranha.core.api.WebApplicationExtension; -import java.io.File; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; -import static java.lang.System.Logger.Level.WARNING; - -/** - * The Builder for Piranha Web Profile. - * - * @author Manfred Riem (mriem@manorrock.com) - */ -public class WebProfilePiranhaBuilder implements PiranhaBuilder { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(WebProfilePiranhaBuilder.class.getName()); - - /** - * Stores the Piranha Web Profile instance. - */ - private final WebProfilePiranha piranha = new WebProfilePiranha(); - - /** - * Stores the verbose flag. - */ - private boolean verbose = false; - - /** - * Build the Piranha instance. - * - * @return the Piranha instance. - */ - public WebProfilePiranha build() { - if (verbose) { - showArguments(); - } - return piranha; - } - - /** - * Set the context path. - * - * @param contextPath the context path. - * @return the builder. - */ - public WebProfilePiranhaBuilder contextPath(String contextPath) { - piranha.getConfiguration().setString("contextPath", contextPath); - return this; - } - - /** - * Set the exit on stop flag. - * - * @param exitOnStop the exit on stop flag. - * @return the builder. - */ - public WebProfilePiranhaBuilder exitOnStop(boolean exitOnStop) { - piranha.getConfiguration().setBoolean("exitOnStop", exitOnStop); - return this; - } - - /** - * Set the extension class. - * - * @param extensionClass the extension class. - * @return the builder. - */ - public WebProfilePiranhaBuilder extensionClass( - Class extensionClass) { - piranha.getConfiguration().setClass("extensionClass", extensionClass); - return this; - } - - /** - * Set the extension class. - * - * @param extensionClassName the default extension class name. - * @return the builder. - */ - public WebProfilePiranhaBuilder extensionClass(String extensionClassName) { - try { - extensionClass(Class.forName(extensionClassName) - .asSubclass(WebApplicationExtension.class)); - } catch (ClassNotFoundException cnfe) { - LOGGER.log(WARNING, "Unable to load extension class", cnfe); - } - return this; - } - - /** - * Set the HTTP server port. - * - * @param httpPort the HTTP server port. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpPort(int httpPort) { - piranha.getConfiguration().setInteger("httpPort", httpPort); - return this; - } - - /** - * Set the HTTP server class. - * - * @param httpServerClass the HTTP server class. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpServerClass(String httpServerClass) { - piranha.getConfiguration().setString("httpServerClass", httpServerClass); - return this; - } - - /** - * Set the HTTPS keystore file. - * - * @param httpsKeystoreFile the HTTPS keystore file. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpsKeystoreFile(String httpsKeystoreFile) { - piranha.getConfiguration().setString("httpsKeystoreFile", httpsKeystoreFile); - return this; - } - - /** - * Set the HTTPS keystore password. - * - * @param httpsKeystorePassword the HTTPS keystore password. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpsKeystorePassword(String httpsKeystorePassword) { - piranha.getConfiguration().setString("httpsKeystorePassword", httpsKeystorePassword); - return this; - } - - /** - * Set the HTTPS server port. - * - * @param httpsPort the HTTPS server port. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpsPort(int httpsPort) { - piranha.getConfiguration().setInteger("httpsPort", httpsPort); - return this; - } - - /** - * Set the HTTPS server class. - * - * @param httpsServerClass the HTTPS server class. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpsServerClass(String httpsServerClass) { - piranha.getConfiguration().setString("httpsServerClass", httpsServerClass); - return this; - } - - /** - * Set the HTTPS truststore file. - * - * @param httpsTruststoreFile the HTTPS truststore file. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpsTruststoreFile(String httpsTruststoreFile) { - piranha.getConfiguration().setString("httpsTruststoreFile", httpsTruststoreFile); - return this; - } - - /** - * Set the HTTPS truststore password. - * - * @param httpsTruststorePassword the HTTPS truststore password. - * @return the builder. - */ - public WebProfilePiranhaBuilder httpsTruststorePassword(String httpsTruststorePassword) { - piranha.getConfiguration().setString("httpsTruststorePassword", httpsTruststorePassword); - return this; - } - - /** - * Enable/disable JPMS. - * - * @param jpms the JPMS flag. - * @return the builder. - */ - public WebProfilePiranhaBuilder jpms(boolean jpms) { - piranha.getConfiguration().setBoolean("jpmsEnabled", jpms); - return this; - } - - /** - * Set the logging level. - * - * @param loggingLevel the logging level. - * @return the builder. - */ - public WebProfilePiranhaBuilder loggingLevel(String loggingLevel) { - piranha.getConfiguration().setString("loggingLevel", loggingLevel); - return this; - } - - /** - * Set the PID. - * - * @param pid the PID. - * @return the builder. - */ - public WebProfilePiranhaBuilder pid(Long pid) { - piranha.getConfiguration().setLong("pid", pid); - return this; - } - - /** - * Show the arguments used. - */ - private void showArguments() { - PiranhaConfiguration configuration = piranha.getConfiguration(); - - LOGGER.log(Level.INFO, - """ - - PIRANHA - - Arguments - ========= - - Context path : %s - Extension class : %s - Exit on stop : %s - HTTP port : %s - HTTP server class : %s - HTTPS keystore file : %s - HTTPS keystore password : **** - HTTPS port : %s - HTTPS server class : %s - HTTPS truststore file : %s - HTTPS truststore password : **** - JPMS enabled : %s - Logging level : %s - PID : %s - WAR filename : %s - Web application dir : %s - - """.formatted( - configuration.getString("contextPath"), - configuration.getClass("extensionClass"), - configuration.getBoolean("exitOnStop", false), - configuration.getInteger("httpPort"), - configuration.getString("httpServerClass"), - configuration.getString("httpsKeystoreFile"), - configuration.getInteger("httpsPort"), - configuration.getString("httpsServerClass"), - configuration.getString("httpsTruststoreFile"), - configuration.getBoolean("jpms", false), - configuration.getString("loggingLevel"), - configuration.getLong("pid"), - configuration.getFile("warFile"), - configuration.getFile("webAppDir") - ) - ); - } - - /** - * Set the verbose flag. - * - * @param verbose the verbose flag. - * @return the builder. - */ - public WebProfilePiranhaBuilder verbose(boolean verbose) { - this.verbose = verbose; - return this; - } - - /** - * Set the WAR file. - * - * @param warFile the WAR file. - * @return the builder. - */ - public WebProfilePiranhaBuilder warFile(String warFile) { - piranha.getConfiguration().setFile("warFile", new File(warFile)); - return this; - } - - /** - * Set the web application directory. - * - * @param webAppDir the web application directory. - * @return the builder. - */ - public WebProfilePiranhaBuilder webAppDir(String webAppDir) { - piranha.getConfiguration().setFile("webAppDir", new File(webAppDir)); - return this; - } -} diff --git a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java b/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java index a993fa11be..177ffcd77e 100644 --- a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java +++ b/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java @@ -28,6 +28,7 @@ package cloud.piranha.dist.webprofile; import cloud.piranha.extension.webprofile.WebProfileExtension; +import cloud.piranha.single.SinglePiranhaBuilder; import static java.lang.System.Logger.Level.WARNING; import java.lang.System.Logger; import java.lang.System.Logger.Level; @@ -50,7 +51,7 @@ public class WebProfilePiranhaMain { * @param arguments the arguments. */ public static void main(String[] arguments) { - WebProfilePiranhaBuilder builder = new WebProfilePiranhaMain().processArguments(arguments); + SinglePiranhaBuilder builder = new WebProfilePiranhaMain().processArguments(arguments); if (builder != null) { builder.build().start(); } else { @@ -63,9 +64,9 @@ public static void main(String[] arguments) { * * @param arguments the arguments. */ - private WebProfilePiranhaBuilder processArguments(String[] arguments) { + private SinglePiranhaBuilder processArguments(String[] arguments) { - WebProfilePiranhaBuilder builder = new WebProfilePiranhaBuilder() + SinglePiranhaBuilder builder = new SinglePiranhaBuilder() .extensionClass(WebProfileExtension.class) .exitOnStop(true); int httpPort = 0; diff --git a/dist/webprofile/src/main/java/module-info.java b/dist/webprofile/src/main/java/module-info.java index 28ae4110aa..96f18525fd 100644 --- a/dist/webprofile/src/main/java/module-info.java +++ b/dist/webprofile/src/main/java/module-info.java @@ -36,10 +36,6 @@ exports cloud.piranha.dist.webprofile; opens cloud.piranha.dist.webprofile; requires cloud.piranha.extension.webprofile; - requires cloud.piranha.feature.exitonstop; - requires cloud.piranha.feature.http; - requires cloud.piranha.feature.https; - requires cloud.piranha.feature.logging; - requires cloud.piranha.feature.webapp; + requires cloud.piranha.single; requires java.logging; } diff --git a/pom.xml b/pom.xml index e9beced812..e386d88e6f 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,7 @@ maven micro resource + single spring diff --git a/single/pom.xml b/single/pom.xml new file mode 100644 index 0000000000..616d094168 --- /dev/null +++ b/single/pom.xml @@ -0,0 +1,133 @@ + + + + 4.0.0 + + cloud.piranha + project + 24.7.0-SNAPSHOT + + piranha-single + jar + Piranha - Single + + + + cloud.piranha + bom + ${project.version} + pom + import + + + + + + + cloud.piranha.core + piranha-core-impl + ${project.version} + compile + + + cloud.piranha.feature + piranha-feature-exitonstop + ${project.version} + compile + + + cloud.piranha.feature + piranha-feature-http + ${project.version} + compile + + + cloud.piranha.feature + piranha-feature-https + ${project.version} + compile + + + cloud.piranha.feature + piranha-feature-impl + ${project.version} + compile + + + cloud.piranha.feature + piranha-feature-logging + ${project.version} + compile + + + cloud.piranha.feature + piranha-feature-webapp + ${project.version} + compile + + + cloud.piranha.http + piranha-http-crac + ${project.version} + compile + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + true + + + + org.jacoco + jacoco-maven-plugin + + + default-check + + check + + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + 0.07 + + + CLASS + MISSEDCOUNT + 3 + + + + + + + + + + + diff --git a/single/src/main/java/cloud/piranha/single/SingleExtension.java b/single/src/main/java/cloud/piranha/single/SingleExtension.java new file mode 100644 index 0000000000..41e8e321d2 --- /dev/null +++ b/single/src/main/java/cloud/piranha/single/SingleExtension.java @@ -0,0 +1,45 @@ +/* + * 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 cloud.piranha.single; + +import cloud.piranha.core.api.WebApplication; +import cloud.piranha.core.api.WebApplicationExtension; + +/** + * The "Solo" WebApplicationExtension. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +public class SingleExtension implements WebApplicationExtension { + + @Override + public void configure(WebApplication webApplication) { + webApplication.addServlet("Solo", SingleServlet.class); + webApplication.addServletMapping("Solo", "/*"); + } +} diff --git a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranha.java b/single/src/main/java/cloud/piranha/single/SinglePiranha.java similarity index 87% rename from dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranha.java rename to single/src/main/java/cloud/piranha/single/SinglePiranha.java index e6ff7311c6..2452958a65 100644 --- a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranha.java +++ b/single/src/main/java/cloud/piranha/single/SinglePiranha.java @@ -25,13 +25,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.dist.webprofile; +package cloud.piranha.single; import cloud.piranha.core.api.Piranha; import cloud.piranha.core.api.PiranhaConfiguration; import cloud.piranha.core.api.WebApplicationExtension; import cloud.piranha.core.impl.DefaultPiranhaConfiguration; -import cloud.piranha.extension.webprofile.WebProfileExtension; import cloud.piranha.feature.api.FeatureManager; import cloud.piranha.feature.exitonstop.ExitOnStopFeature; import cloud.piranha.feature.http.HttpFeature; @@ -44,66 +43,64 @@ 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. + * The Solo version of Piranha. + * + *

+ * This version of Piranha supports the following: + *

+ *
    + *
  1. Enabling use of Project CRaC
  2. + *
  3. Running with Java modules
  4. + *
  5. Exiting on stop
  6. + *
  7. Exposing a HTTP endpoint
  8. + *
  9. Exposing a HTTPS endpoint
  10. + *
  11. Setting the logging level
  12. + *
  13. Hosting a single web application
  14. + *
* * @author Manfred Riem (mriem@manorrock.com) */ -public class WebProfilePiranha implements Piranha, Runnable { +public class SinglePiranha implements Piranha, Runnable { /** * Stores the logger. */ - private static final Logger LOGGER = System.getLogger(WebProfilePiranha.class.getName()); + private static final System.Logger LOGGER = System.getLogger(SinglePiranha.class.getName()); /** * Stores the configuration. */ - private final PiranhaConfiguration configuration; - - /** - * Stores the feature manager. - */ - private final FeatureManager featureManager; - - /** - * Stores the HTTP feature. - */ - private HttpFeature httpFeature; + protected final PiranhaConfiguration configuration; /** - * Stores the HTTPS feature. + * Stores the feature manager. */ - private HttpsFeature httpsFeature; + protected final FeatureManager featureManager; /** * Stores the stop flag. */ - private boolean stop = false; + protected boolean stop = false; /** * Stores the thread we use. */ - private Thread thread; - - /** - * Stores the web application feature; - */ - private WebAppFeature webAppFeature; + protected Thread thread; /** * Constructor. */ - public WebProfilePiranha() { + public SinglePiranha() { configuration = new DefaultPiranhaConfiguration(); + configuration.setClass("extensionClass", SingleExtension.class); configuration.setBoolean("exitOnStop", false); - configuration.setClass("extensionClass", WebProfileExtension.class); + configuration.setBoolean("cracEnabled", false); configuration.setInteger("httpPort", 8080); configuration.setInteger("httpsPort", -1); configuration.setBoolean("jpmsEnabled", false); @@ -121,16 +118,16 @@ public PiranhaConfiguration getConfiguration() { @Override public void run() { long startTime = System.currentTimeMillis(); - + LoggingFeature loggingFeature = new LoggingFeature(); - featureManager.addFeature(loggingFeature); loggingFeature.setLevel(configuration.getString("loggingLevel")); loggingFeature.init(); loggingFeature.start(); + featureManager.addFeature(loggingFeature); LOGGER.log(INFO, () -> "Starting Piranha"); - webAppFeature = new WebAppFeature(); + WebAppFeature webAppFeature = new WebAppFeature(); featureManager.addFeature(webAppFeature); webAppFeature.setContextPath(configuration.getString("contextPath")); webAppFeature.setExtensionClass((Class) configuration.getClass("extensionClass")); @@ -139,17 +136,18 @@ public void run() { webAppFeature.setWebAppDir(configuration.getFile("webAppDir")); webAppFeature.init(); webAppFeature.start(); + featureManager.addFeature(webAppFeature); /* * Construct, initialize and start HTTP endpoint (if applicable). */ if (configuration.getInteger("httpPort") > 0) { - httpFeature = new HttpFeature(); + HttpFeature httpFeature = new HttpFeature(); httpFeature.setHttpServerClass(configuration.getString("httpServerClass")); httpFeature.setPort(configuration.getInteger("httpPort")); httpFeature.init(); httpFeature.getHttpServer().setHttpServerProcessor(webAppFeature.getHttpServerProcessor()); - + /* * Enable Project CRaC. */ @@ -169,15 +167,16 @@ public void run() { } httpFeature.setHttpServer(httpServer); } - + httpFeature.start(); + featureManager.addFeature(httpFeature); } /* * Construct, initialize and start HTTPS endpoint (if applicable). */ if (configuration.getInteger("httpsPort") > 0) { - httpsFeature = new HttpsFeature(); + HttpsFeature httpsFeature = new HttpsFeature(); httpsFeature.setHttpsKeystoreFile(configuration.getString("httpsKeystoreFile")); httpsFeature.setHttpsKeystorePassword(configuration.getString("httpsKeystorePassword")); httpsFeature.setHttpsServerClass(configuration.getString("httpsServerClass")); @@ -202,14 +201,15 @@ public void run() { | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException t) { - LOGGER.log(ERROR, "Unable to construct HTTP server", t); + LOGGER.log(ERROR, "Unable to construct HTTPS server", t); } httpsFeature.setHttpsServer(httpsServer); } httpsFeature.start(); + featureManager.addFeature(httpsFeature); } - + if (configuration.getBoolean("exitOnStop", false)) { ExitOnStopFeature exitOnStopFeature = new ExitOnStopFeature(); featureManager.addFeature(exitOnStopFeature); diff --git a/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaBuilder.java b/single/src/main/java/cloud/piranha/single/SinglePiranhaBuilder.java similarity index 82% rename from dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaBuilder.java rename to single/src/main/java/cloud/piranha/single/SinglePiranhaBuilder.java index f28cfad263..2a67eca2f2 100644 --- a/dist/coreprofile/src/main/java/cloud/piranha/dist/coreprofile/CoreProfilePiranhaBuilder.java +++ b/single/src/main/java/cloud/piranha/single/SinglePiranhaBuilder.java @@ -25,44 +25,45 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.dist.coreprofile; +package cloud.piranha.single; import cloud.piranha.core.api.PiranhaBuilder; import cloud.piranha.core.api.PiranhaConfiguration; import cloud.piranha.core.api.WebApplicationExtension; import java.io.File; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; import static java.lang.System.Logger.Level.WARNING; /** - * The Builder for Piranha Core Profile. - * + * The Solo version of PiranhaBuilder. + * * @author Manfred Riem (mriem@manorrock.com) */ -public class CoreProfilePiranhaBuilder implements PiranhaBuilder { +public class SinglePiranhaBuilder implements PiranhaBuilder { /** * Stores the logger. */ - private static final Logger LOGGER = System.getLogger(CoreProfilePiranhaBuilder.class.getName()); + private static final System.Logger LOGGER = System.getLogger(SinglePiranhaBuilder.class.getName()); /** - * Stores the Piranha instance. + * Stores the SinglePiranha instance. */ - private final CoreProfilePiranha piranha = new CoreProfilePiranha(); - + private SinglePiranha piranha; + /** * Stores the verbose flag. */ private boolean verbose = false; - + /** - * Build the Piranha instance. - * - * @return the Piranha instance. + * Constructor. */ - public CoreProfilePiranha build() { + public SinglePiranhaBuilder() { + piranha = new SinglePiranha(); + } + + @Override + public SinglePiranha build() { if (verbose) { showArguments(); } @@ -75,7 +76,7 @@ public CoreProfilePiranha build() { * @param contextPath the context path. * @return the builder. */ - public CoreProfilePiranhaBuilder contextPath(String contextPath) { + public SinglePiranhaBuilder contextPath(String contextPath) { piranha.getConfiguration().setString("contextPath", contextPath); return this; } @@ -86,7 +87,7 @@ public CoreProfilePiranhaBuilder contextPath(String contextPath) { * @param crac the CRaC enabled flag. * @return the builder. */ - public CoreProfilePiranhaBuilder crac(boolean crac) { + public SinglePiranhaBuilder crac(boolean crac) { piranha.getConfiguration().setBoolean("cracEnabled", crac); return this; } @@ -97,7 +98,7 @@ public CoreProfilePiranhaBuilder crac(boolean crac) { * @param exitOnStop the exit on stop flag. * @return the builder. */ - public CoreProfilePiranhaBuilder exitOnStop(boolean exitOnStop) { + public SinglePiranhaBuilder exitOnStop(boolean exitOnStop) { piranha.getConfiguration().setBoolean("exitOnStop", exitOnStop); return this; } @@ -108,7 +109,7 @@ public CoreProfilePiranhaBuilder exitOnStop(boolean exitOnStop) { * @param extensionClass the extension class. * @return the builder. */ - public CoreProfilePiranhaBuilder extensionClass( + public SinglePiranhaBuilder extensionClass( Class extensionClass) { piranha.getConfiguration().setClass("extensionClass", extensionClass); return this; @@ -120,7 +121,7 @@ public CoreProfilePiranhaBuilder extensionClass( * @param extensionClassName the default extension class name. * @return the builder. */ - public CoreProfilePiranhaBuilder extensionClass(String extensionClassName) { + public SinglePiranhaBuilder extensionClass(String extensionClassName) { try { piranha.getConfiguration().setClass("extensionClass", (Class) Class.forName(extensionClassName)); @@ -136,7 +137,7 @@ public CoreProfilePiranhaBuilder extensionClass(String extensionClassName) { * @param httpPort the HTTP server port. * @return the builder. */ - public CoreProfilePiranhaBuilder httpPort(int httpPort) { + public SinglePiranhaBuilder httpPort(int httpPort) { piranha.getConfiguration().setInteger("httpPort", httpPort); return this; } @@ -147,7 +148,7 @@ public CoreProfilePiranhaBuilder httpPort(int httpPort) { * @param httpServerClass the HTTP server class. * @return the builder. */ - public CoreProfilePiranhaBuilder httpServerClass(String httpServerClass) { + public SinglePiranhaBuilder httpServerClass(String httpServerClass) { piranha.getConfiguration().setString("httpServerClass", httpServerClass); return this; } @@ -158,7 +159,7 @@ public CoreProfilePiranhaBuilder httpServerClass(String httpServerClass) { * @param httpsKeystoreFile the HTTPS keystore file. * @return the builder. */ - public CoreProfilePiranhaBuilder httpsKeystoreFile(String httpsKeystoreFile) { + public SinglePiranhaBuilder httpsKeystoreFile(String httpsKeystoreFile) { piranha.getConfiguration().setString("httpsKeystoreFile", httpsKeystoreFile); return this; } @@ -169,7 +170,7 @@ public CoreProfilePiranhaBuilder httpsKeystoreFile(String httpsKeystoreFile) { * @param httpsKeystorePassword the HTTPS keystore password. * @return the builder. */ - public CoreProfilePiranhaBuilder httpsKeystorePassword(String httpsKeystorePassword) { + public SinglePiranhaBuilder httpsKeystorePassword(String httpsKeystorePassword) { piranha.getConfiguration().setString("httpsKeystorePassword", httpsKeystorePassword); return this; } @@ -180,7 +181,7 @@ public CoreProfilePiranhaBuilder httpsKeystorePassword(String httpsKeystorePassw * @param httpsPort the HTTPS server port. * @return the builder. */ - public CoreProfilePiranhaBuilder httpsPort(int httpsPort) { + public SinglePiranhaBuilder httpsPort(int httpsPort) { piranha.getConfiguration().setInteger("httpsPort", httpsPort); return this; } @@ -191,7 +192,7 @@ public CoreProfilePiranhaBuilder httpsPort(int httpsPort) { * @param httpsServerClass the HTTPS server class. * @return the builder. */ - public CoreProfilePiranhaBuilder httpsServerClass(String httpsServerClass) { + public SinglePiranhaBuilder httpsServerClass(String httpsServerClass) { piranha.getConfiguration().setString("httpsServerClass", httpsServerClass); return this; } @@ -202,7 +203,7 @@ public CoreProfilePiranhaBuilder httpsServerClass(String httpsServerClass) { * @param httpsTruststoreFile the HTTPS truststore file. * @return the builder. */ - public CoreProfilePiranhaBuilder httpsTruststoreFile(String httpsTruststoreFile) { + public SinglePiranhaBuilder httpsTruststoreFile(String httpsTruststoreFile) { piranha.getConfiguration().setString("httpsTruststoreFile", httpsTruststoreFile); return this; } @@ -213,7 +214,7 @@ public CoreProfilePiranhaBuilder httpsTruststoreFile(String httpsTruststoreFile) * @param httpsTruststorePassword the HTTPS truststore password. * @return the builder. */ - public CoreProfilePiranhaBuilder httpsTruststorePassword(String httpsTruststorePassword) { + public SinglePiranhaBuilder httpsTruststorePassword(String httpsTruststorePassword) { piranha.getConfiguration().setString("httpsTruststorePassword", httpsTruststorePassword); return this; } @@ -224,7 +225,7 @@ public CoreProfilePiranhaBuilder httpsTruststorePassword(String httpsTruststoreP * @param jpms the JPMS flag. * @return the builder. */ - public CoreProfilePiranhaBuilder jpms(boolean jpms) { + public SinglePiranhaBuilder jpms(boolean jpms) { piranha.getConfiguration().setBoolean("jpmsEnabled", jpms); return this; } @@ -235,7 +236,7 @@ public CoreProfilePiranhaBuilder jpms(boolean jpms) { * @param loggingLevel the logging level. * @return the builder. */ - public CoreProfilePiranhaBuilder loggingLevel(String loggingLevel) { + public SinglePiranhaBuilder loggingLevel(String loggingLevel) { piranha.getConfiguration().setString("loggingLevel", loggingLevel); return this; } @@ -246,7 +247,7 @@ public CoreProfilePiranhaBuilder loggingLevel(String loggingLevel) { * @param pid the PID. * @return the builder. */ - public CoreProfilePiranhaBuilder pid(Long pid) { + public SinglePiranhaBuilder pid(Long pid) { piranha.getConfiguration().setLong("pid", pid); return this; } @@ -257,7 +258,7 @@ public CoreProfilePiranhaBuilder pid(Long pid) { private void showArguments() { PiranhaConfiguration configuration = piranha.getConfiguration(); - LOGGER.log(Level.INFO, + LOGGER.log(System.Logger.Level.INFO, """ PIRANHA @@ -307,7 +308,7 @@ private void showArguments() { * @param verbose the verbose flag. * @return the builder. */ - public CoreProfilePiranhaBuilder verbose(boolean verbose) { + public SinglePiranhaBuilder verbose(boolean verbose) { this.verbose = verbose; return this; } @@ -318,7 +319,7 @@ public CoreProfilePiranhaBuilder verbose(boolean verbose) { * @param warFile the WAR file. * @return the builder. */ - public CoreProfilePiranhaBuilder warFile(String warFile) { + public SinglePiranhaBuilder warFile(String warFile) { piranha.getConfiguration().setFile("warFile", new File(warFile)); return this; } @@ -329,7 +330,7 @@ public CoreProfilePiranhaBuilder warFile(String warFile) { * @param webAppDir the web application directory. * @return the builder. */ - public CoreProfilePiranhaBuilder webAppDir(String webAppDir) { + public SinglePiranhaBuilder webAppDir(String webAppDir) { piranha.getConfiguration().setFile("webAppDir", new File(webAppDir)); return this; } diff --git a/single/src/main/java/cloud/piranha/single/SingleServlet.java b/single/src/main/java/cloud/piranha/single/SingleServlet.java new file mode 100644 index 0000000000..f018b0132a --- /dev/null +++ b/single/src/main/java/cloud/piranha/single/SingleServlet.java @@ -0,0 +1,38 @@ +/* + * 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 cloud.piranha.single; + +import jakarta.servlet.http.HttpServlet; + +/** + * The "Solo" HttpServlet. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +public class SingleServlet extends HttpServlet { +} diff --git a/single/src/main/java/module-info.java b/single/src/main/java/module-info.java new file mode 100644 index 0000000000..8ee464ab18 --- /dev/null +++ b/single/src/main/java/module-info.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +/** + * This module delivers Piranha Single. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +module cloud.piranha.single { + + exports cloud.piranha.single; + opens cloud.piranha.single; + requires transitive cloud.piranha.core.impl; + requires cloud.piranha.feature.exitonstop; + requires cloud.piranha.feature.http; + requires cloud.piranha.feature.https; + requires cloud.piranha.feature.impl; + requires cloud.piranha.feature.logging; + requires cloud.piranha.feature.webapp; + requires cloud.piranha.http.crac; + requires cloud.piranha.http.webapp; + requires jakarta.servlet; +} diff --git a/dist/servlet/src/test/java/cloud/piranha/dist/servlet/ServletPiranhaBuilderTest.java b/single/src/test/java/cloud/piranha/single/SinglePiranhaBuilderTest.java similarity index 86% rename from dist/servlet/src/test/java/cloud/piranha/dist/servlet/ServletPiranhaBuilderTest.java rename to single/src/test/java/cloud/piranha/single/SinglePiranhaBuilderTest.java index 5a88f9d615..222ca0f32b 100644 --- a/dist/servlet/src/test/java/cloud/piranha/dist/servlet/ServletPiranhaBuilderTest.java +++ b/single/src/test/java/cloud/piranha/single/SinglePiranhaBuilderTest.java @@ -25,20 +25,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.dist.servlet; +package cloud.piranha.single; -import cloud.piranha.extension.servlet.ServletExtension; +import cloud.piranha.single.SinglePiranha; +import cloud.piranha.single.SinglePiranhaBuilder; import java.net.ConnectException; import java.net.Socket; import static org.junit.jupiter.api.Assertions.assertNotNull; import org.junit.jupiter.api.Test; /** - * The JUnit tests for the WebProfilePiranhaBuilder class. + * The JUnit tests for the SinglePiranhaBuilder class. * * @author Manfred Riem (mriem@manorrock.com) */ -class ServletPiranhaBuilderTest { +class SinglePiranhaBuilderTest { /** * Test extensionClass method. @@ -47,8 +48,7 @@ class ServletPiranhaBuilderTest { */ @Test void testExtensionClass() throws Exception { - ServletPiranha piranha = new ServletPiranhaBuilder() - .extensionClass("cloud.piranha.extension.servlet.ServletExtension") + SinglePiranha piranha = new SinglePiranhaBuilder() .httpPort(8080) .verbose(true) .build(); @@ -69,8 +69,7 @@ void testExtensionClass() throws Exception { */ @Test void testExtensionClass2() throws Exception { - ServletPiranha piranha = new ServletPiranhaBuilder() - .extensionClass(ServletExtension.class) + SinglePiranha piranha = new SinglePiranhaBuilder() .httpPort(8081) .verbose(true) .build(); diff --git a/dist/webprofile/src/test/java/cloud/piranha/dist/webprofile/WebProfilePiranhaBuilderTest.java b/single/src/test/java/cloud/piranha/single/SinglePiranhaTest.java similarity index 52% rename from dist/webprofile/src/test/java/cloud/piranha/dist/webprofile/WebProfilePiranhaBuilderTest.java rename to single/src/test/java/cloud/piranha/single/SinglePiranhaTest.java index 1661cb9400..7476165f5d 100644 --- a/dist/webprofile/src/test/java/cloud/piranha/dist/webprofile/WebProfilePiranhaBuilderTest.java +++ b/single/src/test/java/cloud/piranha/single/SinglePiranhaTest.java @@ -25,62 +25,25 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package cloud.piranha.dist.webprofile; +package cloud.piranha.single; -import cloud.piranha.extension.webprofile.WebProfileExtension; -import java.net.ConnectException; -import java.net.Socket; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import cloud.piranha.single.SinglePiranha; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** - * The JUnit tests for the WebProfilePiranhaBuilder class. - * + * The JUnit tests for the SinglePiranha class. + * * @author Manfred Riem (mriem@manorrock.com) */ -class WebProfilePiranhaBuilderTest { - - /** - * Test extensionClass method. - * - * @throws Exception when a serious error occurs. - */ - @Test - void testExtensionClass() throws Exception { - WebProfilePiranha piranha = new WebProfilePiranhaBuilder() - .extensionClass("cloud.piranha.extension.webprofile.WebProfileExtension") - .httpPort(8080) - .verbose(true) - .build(); - piranha.start(); - Thread.sleep(5000); - try ( Socket socket = new Socket("localhost", 8080)) { - assertNotNull(socket.getOutputStream()); - } catch (ConnectException e) { - } - piranha.stop(); - Thread.sleep(5000); - } - +class SinglePiranhaTest { + /** - * Test extensionClass method. - * - * @throws Exception when a serious error occurs. + * Test getConfiguration method. */ @Test - void testExtensionClass2() throws Exception { - WebProfilePiranha piranha = new WebProfilePiranhaBuilder() - .extensionClass(WebProfileExtension.class) - .httpPort(8081) - .verbose(true) - .build(); - piranha.start(); - Thread.sleep(5000); - try ( Socket socket = new Socket("localhost", 8081)) { - assertNotNull(socket.getOutputStream()); - } catch (ConnectException e) { - } - piranha.stop(); - Thread.sleep(5000); + void testGetConfiguration() { + SinglePiranha piranha = new SinglePiranha(); + assertNotNull(piranha.getConfiguration()); } }