X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.cms.lib.jetty%2Fsrc%2Forg%2Fargeo%2Fcms%2Fjetty%2FJettyHttpServer.java;h=80cff8b012bba5e5f55b56dd9a9fcd2e5924eac3;hb=138e686fbf65683c3c94a52f1cfbaf8e02362e19;hp=0eaaadb5f321924cbdee914cf6902119c0a7b50c;hpb=8eb1e5fbb1eecf788e882e52405d8d56b180811c;p=lgpl%2Fargeo-commons.git 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 0eaaadb5f..80cff8b01 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 @@ -10,6 +10,7 @@ import java.util.concurrent.ThreadPoolExecutor; import javax.servlet.ServletException; import org.argeo.api.cms.CmsLog; +import org.argeo.api.cms.CmsState; import org.argeo.cms.CmsDeployProperty; import org.argeo.util.http.HttpServerUtils; import org.eclipse.jetty.http.UriCompliance; @@ -41,7 +42,8 @@ public class JettyHttpServer extends HttpsServer { protected ServerConnector httpConnector; protected ServerConnector httpsConnector; - private InetSocketAddress address; + private InetSocketAddress httpAddress; + private InetSocketAddress httpsAddress; private ThreadPoolExecutor executor; @@ -53,6 +55,8 @@ public class JettyHttpServer extends HttpsServer { private boolean started; + private CmsState cmsState; + @Override public void bind(InetSocketAddress addr, int backlog) throws IOException { throw new UnsupportedOperationException(); @@ -108,6 +112,17 @@ public class JettyHttpServer extends HttpsServer { server.start(); // + // Addresses + String httpHost = getDeployProperty(CmsDeployProperty.HOST); + String fallBackHostname = cmsState != null ? cmsState.getHostname() : "::1"; + if (httpConnector != null) + httpAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname, + httpConnector.getLocalPort()); + if (httpsConnector != null) + httpsAddress = new InetSocketAddress(httpHost != null ? httpHost : fallBackHostname, + httpsConnector.getLocalPort()); + + // Clean up Runtime.getRuntime().addShutdownHook(new Thread(() -> stop(), "Jetty shutdown")); log.info(httpPortsMsg()); @@ -182,7 +197,7 @@ public class JettyHttpServer extends HttpsServer { @Override public InetSocketAddress getAddress() { - return address; + return httpAddress; } @Override @@ -195,8 +210,6 @@ public class JettyHttpServer extends HttpsServer { return httpsConfigurator; } - - protected void configureConnectors() { HttpConfiguration httpConfiguration = new HttpConfiguration(); @@ -210,6 +223,9 @@ public class JettyHttpServer extends HttpsServer { // try { if (httpPortStr != null || httpsPortStr != null) { + // TODO deal with hostname resolving taking too much time +// String fallBackHostname = InetAddress.getLocalHost().getHostName(); + boolean httpEnabled = httpPortStr != null; // props.put(JettyHttpConstants.HTTP_ENABLED, httpEnabled); boolean httpsEnabled = httpsPortStr != null; @@ -226,6 +242,7 @@ public class JettyHttpServer extends HttpsServer { httpConnector.setPort(httpPort); httpConnector.setHost(httpHost); httpConnector.setIdleTimeout(DEFAULT_IDLE_TIMEOUT); + } if (httpsEnabled) { @@ -268,7 +285,8 @@ public class JettyHttpServer extends HttpsServer { } protected String getDeployProperty(CmsDeployProperty deployProperty) { - return System.getProperty(deployProperty.getProperty()); + return cmsState != null ? cmsState.getDeployProperty(deployProperty.getProperty()) + : System.getProperty(deployProperty.getProperty()); } private String httpPortsMsg() { @@ -297,7 +315,10 @@ public class JettyHttpServer extends HttpsServer { } - + public void setCmsState(CmsState cmsState) { + this.cmsState = cmsState; + } + public boolean isStarted() { return started; }