Skip to content

Commit 2b28a66

Browse files
Updated jetty maxFormContentSize value to 1048576 bytes (default is 200000 bytes), to support user data upto 1048576 bytes (apache#8420)
This PR enables support for user data content upto 1048576 bytes - updates jetty maxFormContentSize value to 1048576 bytes (default is 200000 bytes). CloudStack can support max user data content to 1048576 bytes (the size can be configurable through vm.userdata.max.length setting, max 1048576), but it's limited due to the default Jetty max content size, which is 200000 bytes. Configuration Reference from jetty doc: https://eclipse.dev/jetty/documentation/jetty-9/index.html#configuring-specific-webapp-deployment (check with maxFormContentSize here)
1 parent 9a915b1 commit 2b28a66

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

client/conf/server.properties.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ http.port=8080
2929
# Max inactivity time in minutes for the session
3030
session.timeout=30
3131

32+
# Max allowed API request payload / content size in bytes
33+
request.content.size=1048576
34+
3235
# Options to configure and enable HTTPS on management server
3336
#
3437
# For management server to pickup these configuration settings, the configured

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
import java.net.URL;
2727
import java.util.Properties;
2828

29-
import com.cloud.utils.Pair;
30-
import com.cloud.utils.server.ServerProperties;
3129
import org.apache.commons.daemon.Daemon;
3230
import org.apache.commons.daemon.DaemonContext;
31+
import org.apache.commons.lang3.StringUtils;
32+
import org.apache.log4j.Logger;
3333
import org.eclipse.jetty.jmx.MBeanContainer;
3434
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
3535
import org.eclipse.jetty.server.HttpConfiguration;
@@ -40,6 +40,7 @@
4040
import org.eclipse.jetty.server.Server;
4141
import org.eclipse.jetty.server.ServerConnector;
4242
import org.eclipse.jetty.server.SslConnectionFactory;
43+
import org.eclipse.jetty.server.handler.ContextHandler;
4344
import org.eclipse.jetty.server.handler.HandlerCollection;
4445
import org.eclipse.jetty.server.handler.MovedContextHandler;
4546
import org.eclipse.jetty.server.handler.RequestLogHandler;
@@ -50,10 +51,10 @@
5051
import org.eclipse.jetty.util.thread.QueuedThreadPool;
5152
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
5253
import org.eclipse.jetty.webapp.WebAppContext;
53-
import org.apache.log4j.Logger;
5454

55+
import com.cloud.utils.Pair;
5556
import com.cloud.utils.PropertiesUtil;
56-
import org.apache.commons.lang3.StringUtils;
57+
import com.cloud.utils.server.ServerProperties;
5758

5859
/***
5960
* The ServerDaemon class implements the embedded server, it can be started either
@@ -79,6 +80,8 @@ public class ServerDaemon implements Daemon {
7980
private static final String KEYSTORE_PASSWORD = "https.keystore.password";
8081
private static final String WEBAPP_DIR = "webapp.dir";
8182
private static final String ACCESS_LOG = "access.log";
83+
private static final String REQUEST_CONTENT_SIZE_KEY = "request.content.size";
84+
private static final int DEFAULT_REQUEST_CONTENT_SIZE = 1048576;
8285

8386
////////////////////////////////////////////////////////
8487
/////////////// Server Configuration ///////////////////
@@ -90,6 +93,7 @@ public class ServerDaemon implements Daemon {
9093
private int httpPort = 8080;
9194
private int httpsPort = 8443;
9295
private int sessionTimeout = 30;
96+
private int maxFormContentSize = DEFAULT_REQUEST_CONTENT_SIZE;
9397
private boolean httpsEnable = false;
9498
private String accessLogFile = "access.log";
9599
private String bindInterface = null;
@@ -136,6 +140,7 @@ public void init(final DaemonContext context) {
136140
setWebAppLocation(properties.getProperty(WEBAPP_DIR));
137141
setAccessLogFile(properties.getProperty(ACCESS_LOG, "access.log"));
138142
setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30")));
143+
setMaxFormContentSize(Integer.valueOf(properties.getProperty(REQUEST_CONTENT_SIZE_KEY, String.valueOf(DEFAULT_REQUEST_CONTENT_SIZE))));
139144
} catch (final IOException e) {
140145
LOG.warn("Failed to read configuration from server.properties file", e);
141146
} finally {
@@ -186,6 +191,7 @@ public void start() throws Exception {
186191

187192
// Extra config options
188193
server.setStopAtShutdown(true);
194+
server.setAttribute(ContextHandler.MAX_FORM_CONTENT_SIZE_KEY, maxFormContentSize);
189195

190196
// HTTPS Connector
191197
createHttpsConnector(httpConfig);
@@ -257,6 +263,7 @@ private Pair<SessionHandler,HandlerCollection> createHandlers() {
257263
final WebAppContext webApp = new WebAppContext();
258264
webApp.setContextPath(contextPath);
259265
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
266+
webApp.setMaxFormContentSize(maxFormContentSize);
260267

261268
// GZIP handler
262269
final GzipHandler gzipHandler = new GzipHandler();
@@ -355,4 +362,8 @@ public void setWebAppLocation(String webAppLocation) {
355362
public void setSessionTimeout(int sessionTimeout) {
356363
this.sessionTimeout = sessionTimeout;
357364
}
365+
366+
public void setMaxFormContentSize(int maxFormContentSize) {
367+
this.maxFormContentSize = maxFormContentSize;
368+
}
358369
}

0 commit comments

Comments
 (0)