diff --git a/extension/scinitializer/pom.xml b/extension/scinitializer/pom.xml index bba87179e..73b37e085 100644 --- a/extension/scinitializer/pom.xml +++ b/extension/scinitializer/pom.xml @@ -44,5 +44,5 @@ default file:///tmp/piranha/extension/scinitializer - + diff --git a/extension/scinitializer/src/main/java/cloud/piranha/extension/scinitializer/ServletContainerInitializerExtension.java b/extension/scinitializer/src/main/java/cloud/piranha/extension/scinitializer/ServletContainerInitializerExtension.java index 3b5e04b6c..3b70744ae 100644 --- a/extension/scinitializer/src/main/java/cloud/piranha/extension/scinitializer/ServletContainerInitializerExtension.java +++ b/extension/scinitializer/src/main/java/cloud/piranha/extension/scinitializer/ServletContainerInitializerExtension.java @@ -49,6 +49,12 @@ */ public class ServletContainerInitializerExtension implements WebApplicationExtension { + /** + * Stores the ignore initializers property. + */ + public static final String IGNORE_INITIALIZERS_PROPERTY + = ServletContainerInitializerExtension.class.getName() + ".ignoreInitializers"; + /** * Stores the logger. */ @@ -96,6 +102,15 @@ public void configure(WebApplication webApplication) { "cloud.piranha.extension.scinitializer.ServletContainerInitializerExtensionp.enabled", "true"))) { + if (System.getProperty(IGNORE_INITIALIZERS_PROPERTY) != null) { + String[] initializers = System.getProperty(IGNORE_INITIALIZERS_PROPERTY).split(","); + if (initializers.length > 0) { + for(int i=0; i serviceLoader = ServiceLoader.load( ServletContainerInitializer.class, webApplication.getClassLoader()); diff --git a/extension/tyrus/pom.xml b/extension/tyrus/pom.xml index cabc9a770..1e639f2b1 100644 --- a/extension/tyrus/pom.xml +++ b/extension/tyrus/pom.xml @@ -18,6 +18,11 @@ ${project.version} compile + + org.glassfish.tyrus + tyrus-container-servlet + compile + cloud.piranha.extension @@ -25,11 +30,44 @@ ${project.version} provided - + - org.glassfish.tyrus - tyrus-container-servlet - runtime + cloud.piranha.core + piranha-core-impl + ${project.version} + test + + + 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-surefire-plugin + + false + + + + + + + default + file:///tmp/piranha/extension/tyrus + + diff --git a/extension/tyrus/src/main/java/cloud/piranha/extension/tyrus/TyrusExtension.java b/extension/tyrus/src/main/java/cloud/piranha/extension/tyrus/TyrusExtension.java index 8056d9aaf..bc580561b 100644 --- a/extension/tyrus/src/main/java/cloud/piranha/extension/tyrus/TyrusExtension.java +++ b/extension/tyrus/src/main/java/cloud/piranha/extension/tyrus/TyrusExtension.java @@ -30,7 +30,9 @@ import cloud.piranha.core.api.WebApplication; import cloud.piranha.core.api.WebApplicationExtension; import java.lang.System.Logger; +import static java.lang.System.Logger.Level.DEBUG; import static java.lang.System.Logger.Level.TRACE; +import org.glassfish.tyrus.servlet.TyrusServletContainerInitializer; /** * The extension that delivers Tyrus to Piranha. @@ -39,18 +41,41 @@ */ public class TyrusExtension implements WebApplicationExtension { + /** + * Stores the property used for enabling/disabling Tyrus. + */ + public static final String TYRUS_ENABLED_PROPERTY + = "cloud.piranha.extension.tyrus.TyrusExtension.enabled"; + + /** + * Stores the property used for ignore initializers. + */ + private static final String IGNORE_INITIALIZER_PROPERTY + = "cloud.piranha.extension.scinitializer.ServletContainerInitializerExtension.ignoreInitializers"; + /** * Stores the logger. */ private static final Logger LOGGER = System.getLogger(TyrusExtension.class.getName()); - + /** * Configure the extension. - * + * * @param webApplication the web application. */ @Override public void configure(WebApplication webApplication) { - LOGGER.log(TRACE, "Configuring Eclipse Tyrus extension"); + LOGGER.log(DEBUG, "Configuring Tyrus extension"); + + if (!Boolean.parseBoolean(System.getProperty(TYRUS_ENABLED_PROPERTY, "true"))) { + LOGGER.log(TRACE, "Disabling Tyrus extension"); + + String ignoredInitializers = System.getProperty(IGNORE_INITIALIZER_PROPERTY, ""); + if (ignoredInitializers.equals("")) { + ignoredInitializers = TyrusServletContainerInitializer.class.getName(); + } + + System.setProperty(IGNORE_INITIALIZER_PROPERTY, ignoredInitializers); + } } } diff --git a/extension/tyrus/src/main/java/module-info.java b/extension/tyrus/src/main/java/module-info.java index 083019e08..def05fab8 100644 --- a/extension/tyrus/src/main/java/module-info.java +++ b/extension/tyrus/src/main/java/module-info.java @@ -27,12 +27,30 @@ */ /** - * This module integrates Eclipse Tyrus into Piranha. + * This module integrates Tyrus into Piranha. + * + *

+ * The following properties can be used to influence the workings of this module. + *

+ * + * + * + * + * + * + * + * + * + * + *
PropertyNotes
cloud.piranha.extension.tyrus.TyrusExtension.enabledtrue to enable this extension (default), false to disable
Configurable properties
* * @author Manfred Riem (mriem@manorrock.com) */ module cloud.piranha.extension.tyrus { + exports cloud.piranha.extension.tyrus; + opens cloud.piranha.extension.tyrus; requires cloud.piranha.core.api; + requires org.glassfish.tyrus.container.servlet; requires static cloud.piranha.extension.scinitializer; } diff --git a/extension/tyrus/src/test/java/cloud/piranha/extension/tyrus/TyrusExtensionTest.java b/extension/tyrus/src/test/java/cloud/piranha/extension/tyrus/TyrusExtensionTest.java new file mode 100644 index 000000000..df7916c95 --- /dev/null +++ b/extension/tyrus/src/test/java/cloud/piranha/extension/tyrus/TyrusExtensionTest.java @@ -0,0 +1,67 @@ +/* + * 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.extension.tyrus; + +import cloud.piranha.core.impl.DefaultWebApplication; +import cloud.piranha.extension.scinitializer.ServletContainerInitializerExtension; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * The JUnit tests for the TyrusExtension class. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +public class TyrusExtensionTest { + + /** + * Test configure method. + */ + @Test + public void testConfigure() { + DefaultWebApplication webApplication = new DefaultWebApplication(); + TyrusExtension extension = new TyrusExtension(); + extension.configure(webApplication); + assertNull(System.getProperty(TyrusExtension.TYRUS_ENABLED_PROPERTY)); + } + + /** + * Test configure method and disabling Tyrus. + */ + @Test + public void testConfigureAndDisableTyrus() { + DefaultWebApplication webApplication = new DefaultWebApplication(); + TyrusExtension extension = new TyrusExtension(); + System.setProperty(TyrusExtension.TYRUS_ENABLED_PROPERTY, "false"); + extension.configure(webApplication); + assertNotNull(System.getProperty( + ServletContainerInitializerExtension.IGNORE_INITIALIZERS_PROPERTY)); + System.clearProperty(TyrusExtension.TYRUS_ENABLED_PROPERTY); + } +}