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;
/**
* 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.
*/
private int maxHttpHeaderSize = 0;
private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);
/**
* Maximum amount of request body to swallow.
@ -397,11 +397,11 @@ public class ServerProperties {
this.minSpareThreads = minSpareThreads;
}
public int getMaxHttpPostSize() {
public DataSize getMaxHttpPostSize() {
return this.maxHttpPostSize;
}
public void setMaxHttpPostSize(int maxHttpPostSize) {
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpPostSize = maxHttpPostSize;
}
@ -499,12 +499,12 @@ public class ServerProperties {
@Deprecated
@DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")
public int getMaxHttpHeaderSize() {
public DataSize getMaxHttpHeaderSize() {
return this.maxHttpHeaderSize;
}
@Deprecated
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
public void setMaxHttpHeaderSize(DataSize maxHttpHeaderSize) {
this.maxHttpHeaderSize = maxHttpHeaderSize;
}
@ -722,9 +722,9 @@ public class ServerProperties {
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
@ -742,11 +742,11 @@ public class ServerProperties {
return this.accesslog;
}
public int getMaxHttpPostSize() {
public DataSize getMaxHttpPostSize() {
return this.maxHttpPostSize;
}
public void setMaxHttpPostSize(int maxHttpPostSize) {
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpPostSize = maxHttpPostSize;
}
@ -937,16 +937,16 @@ public class ServerProperties {
public static class Undertow {
/**
* Maximum size, in bytes, of the HTTP post content. When the value is -1, the
* default, the size is unlimited.
* Maximum size of the HTTP post content. When the value is -1, the default, the
* 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
* of memory that is available to the JVM.
* Size of each buffer. The default is derived from the maximum amount of memory
* 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
@ -972,19 +972,19 @@ public class ServerProperties {
private final Accesslog accesslog = new Accesslog();
public long getMaxHttpPostSize() {
public DataSize getMaxHttpPostSize() {
return this.maxHttpPostSize;
}
public void setMaxHttpPostSize(long maxHttpPostSize) {
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpPostSize = maxHttpPostSize;
}
public Integer getBufferSize() {
public DataSize getBufferSize() {
return this.bufferSize;
}
public void setBufferSize(Integer bufferSize) {
public void setBufferSize(DataSize bufferSize) {
this.bufferSize = bufferSize;
}

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

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

@ -64,7 +64,8 @@ public class UndertowWebServerFactoryCustomizer implements
ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties
.getAccesslog();
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::getWorkerThreads)
.to(factory::setWorkerThreads);
@ -88,7 +89,8 @@ public class UndertowWebServerFactoryCustomizer implements
.asInt(DataSize::toBytes)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize));
propertyMapper.from(undertowProperties::getMaxHttpPostSize).when(this::isPositive)
propertyMapper.from(undertowProperties::getMaxHttpPostSize).whenNonNull()
.asInt(DataSize::toBytes)
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
maxHttpPostSize));
propertyMapper.from(properties::getConnectionTimeout)

@ -226,7 +226,7 @@ public class ServerPropertiesTests {
@Test
public void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception {
assertThat(this.properties.getTomcat().getMaxHttpPostSize())
assertThat(this.properties.getTomcat().getMaxHttpPostSize().toBytes())
.isEqualTo(getDefaultConnector().getMaxPostSize());
}
@ -333,7 +333,7 @@ public class ServerPropertiesTests {
String message = failure.get().getCause().getMessage();
int defaultMaxPostSize = Integer
.valueOf(message.substring(message.lastIndexOf(' ')).trim());
assertThat(this.properties.getJetty().getMaxHttpPostSize())
assertThat(this.properties.getJetty().getMaxHttpPostSize().toBytes())
.isEqualTo(defaultMaxPostSize);
}
finally {
@ -343,7 +343,7 @@ public class ServerPropertiesTests {
@Test
public void undertowMaxHttpPostSizeMatchesDefault() {
assertThat(this.properties.getUndertow().getMaxHttpPostSize())
assertThat(this.properties.getUndertow().getMaxHttpPostSize().toBytes())
.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\\.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-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-threads=200 # Maximum 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.rotate=true # Whether to enable access log rotation.
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.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.

Loading…
Cancel
Save