Skip to content

Commit cd6288e

Browse files
marcaureleyadvr
authored andcommitted
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
1 parent 3eafd0c commit cd6288e

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

client/conf/server.properties.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ context.path=/client
2424
# The HTTP port to be used by the management server
2525
http.port=8080
2626

27+
# Max inactivity time in minutes for the session
28+
session.timeout=30
29+
2730
# Options to configure and enable HTTPS on management server
2831
#
2932
# For management server to pickup these configuration settings, the configured

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@
491491
<plugin>
492492
<groupId>org.eclipse.jetty</groupId>
493493
<artifactId>jetty-maven-plugin</artifactId>
494-
<version>${cs.jetty.version}</version>
494+
<version>${cs.jetty-maven-plugin.version}</version>
495495
<dependencies>
496496
<!-- specify the dependent jdbc driver here -->
497497
<dependency>

client/src/org/apache/cloudstack/ServerDaemon.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@
2222
import java.io.IOException;
2323
import java.lang.management.ManagementFactory;
2424
import java.net.URL;
25-
import java.util.EnumSet;
26-
import java.util.HashMap;
27-
import java.util.Map;
2825
import java.util.Properties;
2926

30-
import javax.servlet.DispatcherType;
31-
3227
import org.apache.commons.daemon.Daemon;
3328
import org.apache.commons.daemon.DaemonContext;
3429
import org.eclipse.jetty.jmx.MBeanContainer;
@@ -42,9 +37,9 @@
4237
import org.eclipse.jetty.server.ServerConnector;
4338
import org.eclipse.jetty.server.SslConnectionFactory;
4439
import org.eclipse.jetty.server.handler.HandlerCollection;
40+
import org.eclipse.jetty.server.handler.MovedContextHandler;
4541
import org.eclipse.jetty.server.handler.RequestLogHandler;
46-
import org.eclipse.jetty.servlet.FilterHolder;
47-
import org.eclipse.jetty.servlets.GzipFilter;
42+
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
4843
import org.eclipse.jetty.util.ssl.SslContextFactory;
4944
import org.eclipse.jetty.util.thread.QueuedThreadPool;
5045
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
@@ -70,6 +65,7 @@ public class ServerDaemon implements Daemon {
7065

7166
private static final String BIND_INTERFACE = "bind.interface";
7267
private static final String CONTEXT_PATH = "context.path";
68+
private static final String SESSION_TIMEOUT = "session.timeout";
7369
private static final String HTTP_PORT = "http.port";
7470
private static final String HTTPS_ENABLE = "https.enable";
7571
private static final String HTTPS_PORT = "https.port";
@@ -86,6 +82,7 @@ public class ServerDaemon implements Daemon {
8682

8783
private int httpPort = 8080;
8884
private int httpsPort = 8443;
85+
private int sessionTimeout = 30;
8986
private boolean httpsEnable = false;
9087
private String accessLogFile = "access.log";
9188
private String bindInterface = "";
@@ -129,6 +126,7 @@ public void init(final DaemonContext context) {
129126
setKeystorePassword(properties.getProperty(KEYSTORE_PASSWORD));
130127
setWebAppLocation(properties.getProperty(WEBAPP_DIR));
131128
setAccessLogFile(properties.getProperty(ACCESS_LOG, "access.log"));
129+
setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30")));
132130
} catch (final IOException e) {
133131
LOG.warn("Failed to load configuration from server.properties file", e);
134132
}
@@ -221,28 +219,33 @@ private HandlerCollection createHandlers() {
221219
final WebAppContext webApp = new WebAppContext();
222220
webApp.setContextPath(contextPath);
223221
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
222+
webApp.getSessionHandler().setMaxInactiveInterval(sessionTimeout * 60);
224223

225-
final FilterHolder filter = webApp.addFilter(GzipFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
226-
final Map<String, String> params = new HashMap<>();
227-
params.put("mimeTypes", "text/html,text/xml,text/css,text/plain,text/javascript,application/javascript,application/json,application/xml");
228-
params.put("methods", "GET,POST");
229-
params.put("deflateCompressionLevel", "9");
230-
filter.setInitParameters(params);
224+
// GZIP handler
225+
final GzipHandler gzipHandler = new GzipHandler();
226+
gzipHandler.addIncludedMimeTypes("text/html", "text/xml", "text/css", "text/plain", "text/javascript", "application/javascript", "application/json", "application/xml");
227+
gzipHandler.setIncludedMethods("GET", "POST");
228+
gzipHandler.setCompressionLevel(9);
229+
gzipHandler.setHandler(webApp);
231230

232231
if (Strings.isNullOrEmpty(webAppLocation)) {
233232
webApp.setWar(getShadedWarUrl());
234233
} else {
235234
webApp.setWar(webAppLocation);
236235
}
237236

237+
// Request log handler
238238
final RequestLogHandler log = new RequestLogHandler();
239239
log.setRequestLog(createRequestLog());
240240

241-
final HandlerCollection handlerCollection = new HandlerCollection();
242-
handlerCollection.addHandler(log);
243-
handlerCollection.addHandler(webApp);
241+
// Redirect root context handler
242+
MovedContextHandler rootRedirect = new MovedContextHandler();
243+
rootRedirect.setContextPath("/");
244+
rootRedirect.setNewContextURL(contextPath);
245+
rootRedirect.setPermanent(true);
244246

245-
return handlerCollection;
247+
// Put rootRedirect at the end!
248+
return new HandlerCollection(log, gzipHandler, rootRedirect);
246249
}
247250

248251
private RequestLog createRequestLog() {
@@ -307,4 +310,8 @@ public void setAccessLogFile(String accessLogFile) {
307310
public void setWebAppLocation(String webAppLocation) {
308311
this.webAppLocation = webAppLocation;
309312
}
313+
314+
public void setSessionTimeout(int sessionTimeout) {
315+
this.sessionTimeout = sessionTimeout;
316+
}
310317
}

plugins/integrations/cloudian/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</dependency>
5353
<dependency>
5454
<groupId>com.github.tomakehurst</groupId>
55-
<artifactId>wiremock</artifactId>
55+
<artifactId>wiremock-standalone</artifactId>
5656
<version>${cs.wiremock.version}</version>
5757
<scope>test</scope>
5858
</dependency>

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@
120120
<cs.cxf.version>3.2.0</cs.cxf.version>
121121
<cs.groovy.version>2.4.12</cs.groovy.version>
122122
<cs.nitro.version>10.1</cs.nitro.version>
123-
<cs.wiremock.version>2.8.0</cs.wiremock.version>
124-
<cs.jetty.version>9.2.22.v20170606</cs.jetty.version>
123+
<cs.wiremock.version>2.11.0</cs.wiremock.version>
124+
<cs.jetty.version>9.4.7.v20170914</cs.jetty.version>
125+
<cs.jetty-maven-plugin.version>9.2.22.v20170606</cs.jetty-maven-plugin.version>
125126
</properties>
126127

127128
<distributionManagement>

0 commit comments

Comments
 (0)