Clarify Jetty server code
[lgpl/argeo-commons.git] / org.argeo.cms.lib.jetty / src / org / argeo / cms / jetty / JettyHttpServer.java
index 11cce74cdc2e1b50a0b8294fa0b30a8d61a27c45..b670e5cf1bd1aca086a1289f0752dbade096032c 100644 (file)
@@ -13,7 +13,7 @@ import javax.websocket.server.ServerContainer;
 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.argeo.cms.http.HttpServerUtils;
 import org.eclipse.jetty.http.UriCompliance;
 import org.eclipse.jetty.server.HttpConfiguration;
 import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -131,8 +131,6 @@ public class JettyHttpServer extends HttpsServer {
        }
 
        protected void configureConnectors() {
-               HttpConfiguration httpConfiguration = new HttpConfiguration();
-
                String httpPortStr = getDeployProperty(CmsDeployProperty.HTTP_PORT);
                String httpsPortStr = getDeployProperty(CmsDeployProperty.HTTPS_PORT);
                if (httpPortStr != null && httpsPortStr != null)
@@ -151,13 +149,15 @@ public class JettyHttpServer extends HttpsServer {
                        boolean httpEnabled = httpPortStr != null;
                        boolean httpsEnabled = httpsPortStr != null;
 
-                       if (httpsEnabled) {
-                               int httpsPort = Integer.parseInt(httpsPortStr);
-                               httpConfiguration.setSecureScheme("https");
-                               httpConfiguration.setSecurePort(httpsPort);
-                       }
-
                        if (httpEnabled) {
+                               HttpConfiguration httpConfiguration = new HttpConfiguration();
+
+                               if (httpsEnabled) {// not supported anymore to have both http and https, but it may change again
+                                       int httpsPort = Integer.parseInt(httpsPortStr);
+                                       httpConfiguration.setSecureScheme("https");
+                                       httpConfiguration.setSecurePort(httpsPort);
+                               }
+
                                int httpPort = Integer.parseInt(httpPortStr);
                                httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
                                httpConnector.setPort(httpPort);
@@ -188,13 +188,13 @@ public class JettyHttpServer extends HttpsServer {
                                        sslContextFactory.setNeedClientAuth(true);
 
                                // HTTPS Configuration
-                               HttpConfiguration https_config = new HttpConfiguration(httpConfiguration);
-                               https_config.addCustomizer(new SecureRequestCustomizer());
-                               https_config.setUriCompliance(UriCompliance.LEGACY);
+                               HttpConfiguration httpsConfiguration = new HttpConfiguration();
+                               httpsConfiguration.addCustomizer(new SecureRequestCustomizer());
+                               httpsConfiguration.setUriCompliance(UriCompliance.LEGACY);
 
                                // HTTPS connector
                                httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"),
-                                               new HttpConnectionFactory(https_config));
+                                               new HttpConnectionFactory(httpsConfiguration));
                                int httpsPort = Integer.parseInt(httpsPortStr);
                                httpsConnector.setPort(httpsPort);
                                httpsConnector.setHost(httpHost);
@@ -241,10 +241,10 @@ public class JettyHttpServer extends HttpsServer {
 
        @Override
        public synchronized HttpContext createContext(String path) {
+               if (!path.endsWith("/"))
+                       path = path + "/";
                if (contexts.containsKey(path))
                        throw new IllegalArgumentException("Context " + path + " already exists");
-               if (!path.endsWith("/"))
-                       throw new IllegalArgumentException("Path " + path + " should end with a /");
 
                JettyHttpContext httpContext = new ServletHttpContext(this, path);
                contexts.put(path, httpContext);