From: Mathieu Baudier Date: Tue, 30 May 2023 11:47:43 +0000 (+0200) Subject: Do not start Jetty if not ports defined X-Git-Tag: v2.3.17~4 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=f1439aea3c73fbcc3c9c6f0e31efe83144fdba1a;p=lgpl%2Fargeo-commons.git Do not start Jetty if not ports defined --- diff --git a/org.argeo.cms.lib.jetty/src/org/argeo/cms/jetty/JettyHttpServer.java b/org.argeo.cms.lib.jetty/src/org/argeo/cms/jetty/JettyHttpServer.java index 5f1173ce4..e994463f9 100644 --- a/org.argeo.cms.lib.jetty/src/org/argeo/cms/jetty/JettyHttpServer.java +++ b/org.argeo.cms.lib.jetty/src/org/argeo/cms/jetty/JettyHttpServer.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.util.thread.ThreadPool; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsServer; @@ -68,6 +69,17 @@ public class JettyHttpServer extends HttpsServer { @Override public void start() { + String httpPortStr = getDeployProperty(CmsDeployProperty.HTTP_PORT); + String httpsPortStr = getDeployProperty(CmsDeployProperty.HTTPS_PORT); + if (httpPortStr != null && httpsPortStr != null) + throw new IllegalArgumentException("Either an HTTP or an HTTPS port should be configured, not both"); + if (httpPortStr == null && httpsPortStr == null) { + log.warn("Neither an HTTP or an HTTPS port was configured, not starting Jetty"); + } + + /// TODO make it more generic + String httpHost = getDeployProperty(CmsDeployProperty.HOST); + try { ThreadPool threadPool = null; @@ -80,7 +92,7 @@ public class JettyHttpServer extends HttpsServer { server = new Server(threadPool); - configureConnectors(); + configureConnectors(httpPortStr, httpsPortStr, httpHost); if (httpConnector != null) { httpConnector.open(); @@ -111,7 +123,6 @@ public class JettyHttpServer extends HttpsServer { // // Addresses - String httpHost = getDeployProperty(CmsDeployProperty.HOST); String fallBackHostname = cmsState != null ? cmsState.getHostname() : "::1"; if (httpConnector != null) { httpAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname, @@ -131,16 +142,7 @@ public class JettyHttpServer extends HttpsServer { } } - protected void configureConnectors() { - String httpPortStr = getDeployProperty(CmsDeployProperty.HTTP_PORT); - String httpsPortStr = getDeployProperty(CmsDeployProperty.HTTPS_PORT); - if (httpPortStr != null && httpsPortStr != null) - throw new IllegalArgumentException("Either an HTTP or an HTTPS port should be configured, not both"); - if (httpPortStr == null && httpsPortStr == null) - throw new IllegalArgumentException("Neither an HTTP or HTTPS port was configured"); - - /// TODO make it more generic - String httpHost = getDeployProperty(CmsDeployProperty.HOST); + protected void configureConnectors(String httpPortStr, String httpsPortStr, String httpHost) { // try { if (httpPortStr != null || httpsPortStr != null) {