Improve RCP launch
[lgpl/argeo-commons.git] / org.argeo.cms.lib.jetty / src / org / argeo / cms / jetty / JettyHttpServer.java
index a469a87c4ec8b22ca4b1f7a0dafc095502f613de..98975c3c843ad7c152a4c1815f738a812c6ca130 100644 (file)
@@ -2,11 +2,13 @@ package org.argeo.cms.jetty;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.security.NoSuchAlgorithmException;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ThreadPoolExecutor;
 
+import javax.net.ssl.SSLContext;
 import javax.servlet.ServletException;
 import javax.websocket.server.ServerContainer;
 
@@ -170,6 +172,16 @@ public class JettyHttpServer extends HttpsServer {
                        }
 
                        if (httpsEnabled) {
+                               if (httpsConfigurator == null) {
+                                       // we make sure that an HttpSConfigurator is set, so that clients can detect
+                                       // whether this server is HTTP or HTTPS
+                                       try {
+                                               httpsConfigurator = new HttpsConfigurator(SSLContext.getDefault());
+                                       } catch (NoSuchAlgorithmException e) {
+                                               throw new IllegalStateException("Cannot initalise SSL Context", e);
+                                       }
+                               }
+
                                SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
                                // sslContextFactory.setKeyStore(KeyS)
 
@@ -267,6 +279,9 @@ public class JettyHttpServer extends HttpsServer {
                if (httpContext instanceof ContextHandlerHttpContext contextHandlerHttpContext) {
                        // TODO stop handler first?
                        contextHandlerCollection.removeHandler(contextHandlerHttpContext.getServletContextHandler());
+               } else {
+                       // FIXME apparently servlets cannot be removed in Jetty, we should replace the
+                       // handler
                }
        }