Migrate size properties to DataSize

See gh-14549
pull/14569/merge
qct 6 years ago committed by Stephane Nicoll
parent def02deaf0
commit eb9f635004

@ -325,14 +325,14 @@ public class ServerProperties {
private int minSpareThreads = 10; private int minSpareThreads = 10;
/** /**
* Maximum size, in bytes, of the HTTP post content. * Maximum size of the HTTP post content.
*/ */
private int maxHttpPostSize = 2097152; private DataSize maxHttpPostSize = DataSize.ofMegabytes(2);
/** /**
* Maximum size, in bytes, of the HTTP message header. * Maximum size, in bytes, of the HTTP message header.
*/ */
private int maxHttpHeaderSize = 0; private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);
/** /**
* Maximum amount of request body to swallow. * Maximum amount of request body to swallow.
@ -397,11 +397,11 @@ public class ServerProperties {
this.minSpareThreads = minSpareThreads; this.minSpareThreads = minSpareThreads;
} }
public int getMaxHttpPostSize() { public DataSize getMaxHttpPostSize() {
return this.maxHttpPostSize; return this.maxHttpPostSize;
} }
public void setMaxHttpPostSize(int maxHttpPostSize) { public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpPostSize = maxHttpPostSize; this.maxHttpPostSize = maxHttpPostSize;
} }
@ -499,12 +499,12 @@ public class ServerProperties {
@Deprecated @Deprecated
@DeprecatedConfigurationProperty(replacement = "server.max-http-header-size") @DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")
public int getMaxHttpHeaderSize() { public DataSize getMaxHttpHeaderSize() {
return this.maxHttpHeaderSize; return this.maxHttpHeaderSize;
} }
@Deprecated @Deprecated
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) { public void setMaxHttpHeaderSize(DataSize maxHttpHeaderSize) {
this.maxHttpHeaderSize = maxHttpHeaderSize; this.maxHttpHeaderSize = maxHttpHeaderSize;
} }
@ -722,9 +722,9 @@ public class ServerProperties {
private final Accesslog accesslog = new Accesslog(); private final Accesslog accesslog = new Accesslog();
/** /**
* Maximum size, in bytes, of the HTTP post or put content. * Maximum size of the HTTP post or put content.
*/ */
private int maxHttpPostSize = 200000; // bytes private DataSize maxHttpPostSize = DataSize.ofBytes(200000);
/** /**
* Number of acceptor threads to use. When the value is -1, the default, the * Number of acceptor threads to use. When the value is -1, the default, the
@ -742,11 +742,11 @@ public class ServerProperties {
return this.accesslog; return this.accesslog;
} }
public int getMaxHttpPostSize() { public DataSize getMaxHttpPostSize() {
return this.maxHttpPostSize; return this.maxHttpPostSize;
} }
public void setMaxHttpPostSize(int maxHttpPostSize) { public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpPostSize = maxHttpPostSize; this.maxHttpPostSize = maxHttpPostSize;
} }
@ -937,16 +937,16 @@ public class ServerProperties {
public static class Undertow { public static class Undertow {
/** /**
* Maximum size, in bytes, of the HTTP post content. When the value is -1, the * Maximum size of the HTTP post content. When the value is -1, the default, the
* default, the size is unlimited. * size is unlimited.
*/ */
private long maxHttpPostSize = -1; // bytes private DataSize maxHttpPostSize = DataSize.ofBytes(-1);
/** /**
* Size of each buffer, in bytes. The default is derived from the maximum amount * Size of each buffer. The default is derived from the maximum amount of memory
* of memory that is available to the JVM. * that is available to the JVM.
*/ */
private Integer bufferSize; private DataSize bufferSize = DataSize.ofBytes(0);
/** /**
* Number of I/O threads to create for the worker. The default is derived from the * Number of I/O threads to create for the worker. The default is derived from the
@ -972,19 +972,19 @@ public class ServerProperties {
private final Accesslog accesslog = new Accesslog(); private final Accesslog accesslog = new Accesslog();
public long getMaxHttpPostSize() { public DataSize getMaxHttpPostSize() {
return this.maxHttpPostSize; return this.maxHttpPostSize;
} }
public void setMaxHttpPostSize(long maxHttpPostSize) { public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpPostSize = maxHttpPostSize; this.maxHttpPostSize = maxHttpPostSize;
} }
public Integer getBufferSize() { public DataSize getBufferSize() {
return this.bufferSize; return this.bufferSize;
} }
public void setBufferSize(Integer bufferSize) { public void setBufferSize(DataSize bufferSize) {
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
} }

@ -78,7 +78,8 @@ public class JettyWebServerFactoryCustomizer implements
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, .to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize)); maxHttpHeaderSize));
propertyMapper.from(jettyProperties::getMaxHttpPostSize).when(this::isPositive) propertyMapper.from(jettyProperties::getMaxHttpPostSize).whenNonNull()
.asInt(DataSize::toBytes)
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
maxHttpPostSize)); maxHttpPostSize));
propertyMapper.from(properties::getConnectionTimeout).whenNonNull() propertyMapper.from(properties::getConnectionTimeout).whenNonNull()

@ -92,8 +92,8 @@ public class TomcatWebServerFactoryCustomizer implements
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull() propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull()
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize)); .to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
propertyMapper.from(tomcatProperties::getMaxHttpPostSize) propertyMapper.from(tomcatProperties::getMaxHttpPostSize).whenNonNull()
.when((maxHttpPostSize) -> maxHttpPostSize != 0) .asInt(DataSize::toBytes)
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
maxHttpPostSize)); maxHttpPostSize));
propertyMapper.from(tomcatProperties::getAccesslog) propertyMapper.from(tomcatProperties::getAccesslog)
@ -118,9 +118,8 @@ public class TomcatWebServerFactoryCustomizer implements
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private DataSize determineMaxHttpHeaderSize() { private DataSize determineMaxHttpHeaderSize() {
return isPositive(this.serverProperties.getTomcat().getMaxHttpHeaderSize()) return (this.serverProperties.getTomcat().getMaxHttpHeaderSize().toBytes() > 0)
? DataSize ? this.serverProperties.getTomcat().getMaxHttpHeaderSize()
.ofBytes(this.serverProperties.getTomcat().getMaxHttpHeaderSize())
: this.serverProperties.getMaxHttpHeaderSize(); : this.serverProperties.getMaxHttpHeaderSize();
} }

@ -64,7 +64,8 @@ public class UndertowWebServerFactoryCustomizer implements
ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties
.getAccesslog(); .getAccesslog();
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
propertyMapper.from(undertowProperties::getBufferSize).to(factory::setBufferSize); propertyMapper.from(undertowProperties::getBufferSize).whenNonNull()
.asInt(DataSize::toBytes).to(factory::setBufferSize);
propertyMapper.from(undertowProperties::getIoThreads).to(factory::setIoThreads); propertyMapper.from(undertowProperties::getIoThreads).to(factory::setIoThreads);
propertyMapper.from(undertowProperties::getWorkerThreads) propertyMapper.from(undertowProperties::getWorkerThreads)
.to(factory::setWorkerThreads); .to(factory::setWorkerThreads);
@ -88,7 +89,8 @@ public class UndertowWebServerFactoryCustomizer implements
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, .to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize)); maxHttpHeaderSize));
propertyMapper.from(undertowProperties::getMaxHttpPostSize).when(this::isPositive) propertyMapper.from(undertowProperties::getMaxHttpPostSize).whenNonNull()
.asInt(DataSize::toBytes)
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
maxHttpPostSize)); maxHttpPostSize));
propertyMapper.from(properties::getConnectionTimeout) propertyMapper.from(properties::getConnectionTimeout)

@ -226,7 +226,7 @@ public class ServerPropertiesTests {
@Test @Test
public void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception { public void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception {
assertThat(this.properties.getTomcat().getMaxHttpPostSize()) assertThat(this.properties.getTomcat().getMaxHttpPostSize().toBytes())
.isEqualTo(getDefaultConnector().getMaxPostSize()); .isEqualTo(getDefaultConnector().getMaxPostSize());
} }
@ -333,7 +333,7 @@ public class ServerPropertiesTests {
String message = failure.get().getCause().getMessage(); String message = failure.get().getCause().getMessage();
int defaultMaxPostSize = Integer int defaultMaxPostSize = Integer
.valueOf(message.substring(message.lastIndexOf(' ')).trim()); .valueOf(message.substring(message.lastIndexOf(' ')).trim());
assertThat(this.properties.getJetty().getMaxHttpPostSize()) assertThat(this.properties.getJetty().getMaxHttpPostSize().toBytes())
.isEqualTo(defaultMaxPostSize); .isEqualTo(defaultMaxPostSize);
} }
finally { finally {
@ -343,7 +343,7 @@ public class ServerPropertiesTests {
@Test @Test
public void undertowMaxHttpPostSizeMatchesDefault() { public void undertowMaxHttpPostSizeMatchesDefault() {
assertThat(this.properties.getUndertow().getMaxHttpPostSize()) assertThat(this.properties.getUndertow().getMaxHttpPostSize().toBytes())
.isEqualTo(UndertowOptions.DEFAULT_MAX_ENTITY_SIZE); .isEqualTo(UndertowOptions.DEFAULT_MAX_ENTITY_SIZE);
} }

@ -263,7 +263,7 @@ content into your application. Rather, pick only the properties that you need.
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\ 172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # Regular expression matching trusted IP addresses. 172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # Regular expression matching trusted IP addresses.
server.tomcat.max-connections=10000 # Maximum number of connections that the server will accept and process at any given time. server.tomcat.max-connections=10000 # Maximum number of connections that the server will accept and process at any given time.
server.tomcat.max-http-post-size=2097152 # Maximum size in bytes of the HTTP post content. server.tomcat.max-http-post-size=2MB # Maximum size of the HTTP post content.
server.tomcat.max-swallow-size=2MB # Maximum amount of request body to swallow. server.tomcat.max-swallow-size=2MB # Maximum amount of request body to swallow.
server.tomcat.max-threads=200 # Maximum amount of worker threads. server.tomcat.max-threads=200 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=10 # Minimum amount of worker threads. server.tomcat.min-spare-threads=10 # Minimum amount of worker threads.
@ -282,7 +282,7 @@ content into your application. Rather, pick only the properties that you need.
server.undertow.accesslog.prefix=access_log. # Log file name prefix. server.undertow.accesslog.prefix=access_log. # Log file name prefix.
server.undertow.accesslog.rotate=true # Whether to enable access log rotation. server.undertow.accesslog.rotate=true # Whether to enable access log rotation.
server.undertow.accesslog.suffix=log # Log file name suffix. server.undertow.accesslog.suffix=log # Log file name suffix.
server.undertow.buffer-size= # Size of each buffer, in bytes. server.undertow.buffer-size=0 # Size of each buffer, in bytes.
server.undertow.direct-buffers= # Allocate buffers outside the Java heap. The default is derived from the maximum amount of memory that is available to the JVM. server.undertow.direct-buffers= # Allocate buffers outside the Java heap. The default is derived from the maximum amount of memory that is available to the JVM.
server.undertow.eager-filter-init=true # Whether servlet filters should be initialized on startup. server.undertow.eager-filter-init=true # Whether servlet filters should be initialized on startup.
server.undertow.io-threads= # Number of I/O threads to create for the worker. The default is derived from the number of available processors. server.undertow.io-threads= # Number of I/O threads to create for the worker. The default is derived from the number of available processors.

Loading…
Cancel
Save