CLOUDSTACK-10012: Jetty 9.4 (#2329)

* Bump Jetty to 9.4

* Use new jetty gzip handler

* Redirect / to context

* Update wiremock but still not working

* Add session timeout configuration

* server.properties.in: Change default timeout to 30 (mins)

* cloudian: fix unit test failures

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

* client: use older 9.2.x jetty-maven-plugin that works

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

* Moving jetty mvn plugin version in properties

Signed-off-by: Marc-Aurèle Brothier <m@brothier.org>

* Set default session timeout to 30mins
This commit is contained in:
Marc-Aurèle Brothier 2017-11-17 18:56:02 +01:00 committed by Rohit Yadav
parent 3eafd0ce52
commit cd6288ecfb
5 changed files with 32 additions and 21 deletions

View File

@ -24,6 +24,9 @@ context.path=/client
# The HTTP port to be used by the management server # The HTTP port to be used by the management server
http.port=8080 http.port=8080
# Max inactivity time in minutes for the session
session.timeout=30
# Options to configure and enable HTTPS on management server # Options to configure and enable HTTPS on management server
# #
# For management server to pickup these configuration settings, the configured # For management server to pickup these configuration settings, the configured

View File

@ -491,7 +491,7 @@
<plugin> <plugin>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId> <artifactId>jetty-maven-plugin</artifactId>
<version>${cs.jetty.version}</version> <version>${cs.jetty-maven-plugin.version}</version>
<dependencies> <dependencies>
<!-- specify the dependent jdbc driver here --> <!-- specify the dependent jdbc driver here -->
<dependency> <dependency>

View File

@ -22,13 +22,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.net.URL; import java.net.URL;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.servlet.DispatcherType;
import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext; import org.apache.commons.daemon.DaemonContext;
import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.jmx.MBeanContainer;
@ -42,9 +37,9 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory; import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.MovedContextHandler;
import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.servlets.GzipFilter;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
@ -70,6 +65,7 @@ public class ServerDaemon implements Daemon {
private static final String BIND_INTERFACE = "bind.interface"; private static final String BIND_INTERFACE = "bind.interface";
private static final String CONTEXT_PATH = "context.path"; private static final String CONTEXT_PATH = "context.path";
private static final String SESSION_TIMEOUT = "session.timeout";
private static final String HTTP_PORT = "http.port"; private static final String HTTP_PORT = "http.port";
private static final String HTTPS_ENABLE = "https.enable"; private static final String HTTPS_ENABLE = "https.enable";
private static final String HTTPS_PORT = "https.port"; private static final String HTTPS_PORT = "https.port";
@ -86,6 +82,7 @@ public class ServerDaemon implements Daemon {
private int httpPort = 8080; private int httpPort = 8080;
private int httpsPort = 8443; private int httpsPort = 8443;
private int sessionTimeout = 30;
private boolean httpsEnable = false; private boolean httpsEnable = false;
private String accessLogFile = "access.log"; private String accessLogFile = "access.log";
private String bindInterface = ""; private String bindInterface = "";
@ -129,6 +126,7 @@ public class ServerDaemon implements Daemon {
setKeystorePassword(properties.getProperty(KEYSTORE_PASSWORD)); setKeystorePassword(properties.getProperty(KEYSTORE_PASSWORD));
setWebAppLocation(properties.getProperty(WEBAPP_DIR)); setWebAppLocation(properties.getProperty(WEBAPP_DIR));
setAccessLogFile(properties.getProperty(ACCESS_LOG, "access.log")); setAccessLogFile(properties.getProperty(ACCESS_LOG, "access.log"));
setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30")));
} catch (final IOException e) { } catch (final IOException e) {
LOG.warn("Failed to load configuration from server.properties file", e); LOG.warn("Failed to load configuration from server.properties file", e);
} }
@ -221,13 +219,14 @@ public class ServerDaemon implements Daemon {
final WebAppContext webApp = new WebAppContext(); final WebAppContext webApp = new WebAppContext();
webApp.setContextPath(contextPath); webApp.setContextPath(contextPath);
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
webApp.getSessionHandler().setMaxInactiveInterval(sessionTimeout * 60);
final FilterHolder filter = webApp.addFilter(GzipFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); // GZIP handler
final Map<String, String> params = new HashMap<>(); final GzipHandler gzipHandler = new GzipHandler();
params.put("mimeTypes", "text/html,text/xml,text/css,text/plain,text/javascript,application/javascript,application/json,application/xml"); gzipHandler.addIncludedMimeTypes("text/html", "text/xml", "text/css", "text/plain", "text/javascript", "application/javascript", "application/json", "application/xml");
params.put("methods", "GET,POST"); gzipHandler.setIncludedMethods("GET", "POST");
params.put("deflateCompressionLevel", "9"); gzipHandler.setCompressionLevel(9);
filter.setInitParameters(params); gzipHandler.setHandler(webApp);
if (Strings.isNullOrEmpty(webAppLocation)) { if (Strings.isNullOrEmpty(webAppLocation)) {
webApp.setWar(getShadedWarUrl()); webApp.setWar(getShadedWarUrl());
@ -235,14 +234,18 @@ public class ServerDaemon implements Daemon {
webApp.setWar(webAppLocation); webApp.setWar(webAppLocation);
} }
// Request log handler
final RequestLogHandler log = new RequestLogHandler(); final RequestLogHandler log = new RequestLogHandler();
log.setRequestLog(createRequestLog()); log.setRequestLog(createRequestLog());
final HandlerCollection handlerCollection = new HandlerCollection(); // Redirect root context handler
handlerCollection.addHandler(log); MovedContextHandler rootRedirect = new MovedContextHandler();
handlerCollection.addHandler(webApp); rootRedirect.setContextPath("/");
rootRedirect.setNewContextURL(contextPath);
rootRedirect.setPermanent(true);
return handlerCollection; // Put rootRedirect at the end!
return new HandlerCollection(log, gzipHandler, rootRedirect);
} }
private RequestLog createRequestLog() { private RequestLog createRequestLog() {
@ -307,4 +310,8 @@ public class ServerDaemon implements Daemon {
public void setWebAppLocation(String webAppLocation) { public void setWebAppLocation(String webAppLocation) {
this.webAppLocation = webAppLocation; this.webAppLocation = webAppLocation;
} }
public void setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
} }

View File

@ -52,7 +52,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.tomakehurst</groupId> <groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId> <artifactId>wiremock-standalone</artifactId>
<version>${cs.wiremock.version}</version> <version>${cs.wiremock.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@ -120,8 +120,9 @@
<cs.cxf.version>3.2.0</cs.cxf.version> <cs.cxf.version>3.2.0</cs.cxf.version>
<cs.groovy.version>2.4.12</cs.groovy.version> <cs.groovy.version>2.4.12</cs.groovy.version>
<cs.nitro.version>10.1</cs.nitro.version> <cs.nitro.version>10.1</cs.nitro.version>
<cs.wiremock.version>2.8.0</cs.wiremock.version> <cs.wiremock.version>2.11.0</cs.wiremock.version>
<cs.jetty.version>9.2.22.v20170606</cs.jetty.version> <cs.jetty.version>9.4.7.v20170914</cs.jetty.version>
<cs.jetty-maven-plugin.version>9.2.22.v20170606</cs.jetty-maven-plugin.version>
</properties> </properties>
<distributionManagement> <distributionManagement>