This commit is contained in:
Phillip Webb 2023-02-23 13:00:30 -08:00
parent 982e922c0b
commit b20b5edf2a
6 changed files with 67 additions and 79 deletions

View File

@ -77,10 +77,7 @@ class HazelcastServerConfiguration {
private Config loadConfig(Resource configLocation) throws IOException { private Config loadConfig(Resource configLocation) throws IOException {
URL configUrl = configLocation.getURL(); URL configUrl = configLocation.getURL();
Config config; Config config = loadConfig(configUrl);
try (InputStream stream = configUrl.openStream()) {
config = Config.loadFromStream(stream);
}
if (ResourceUtils.isFileURL(configUrl)) { if (ResourceUtils.isFileURL(configUrl)) {
config.setConfigurationFile(configLocation.getFile()); config.setConfigurationFile(configLocation.getFile());
} }
@ -90,6 +87,12 @@ class HazelcastServerConfiguration {
return config; return config;
} }
private Config loadConfig(URL configUrl) throws IOException {
try (InputStream stream = configUrl.openStream()) {
return Config.loadFromStream(stream);
}
}
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)

View File

@ -76,34 +76,29 @@ public class JettyWebServerFactoryCustomizer
@Override @Override
public void customize(ConfigurableJettyWebServerFactory factory) { public void customize(ConfigurableJettyWebServerFactory factory) {
ServerProperties properties = this.serverProperties; ServerProperties.Jetty properties = this.serverProperties.getJetty();
ServerProperties.Jetty jettyProperties = properties.getJetty();
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders()); factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
ServerProperties.Jetty.Threads threadProperties = jettyProperties.getThreads(); ServerProperties.Jetty.Threads threadProperties = properties.getThreads();
factory.setThreadPool(determineThreadPool(jettyProperties.getThreads())); factory.setThreadPool(determineThreadPool(properties.getThreads()));
PropertyMapper propertyMapper = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
propertyMapper.from(threadProperties::getAcceptors).whenNonNull().to(factory::setAcceptors); map.from(threadProperties::getAcceptors).to(factory::setAcceptors);
propertyMapper.from(threadProperties::getSelectors).whenNonNull().to(factory::setSelectors); map.from(threadProperties::getSelectors).to(factory::setSelectors);
propertyMapper.from(properties::getMaxHttpRequestHeaderSize) map.from(this.serverProperties::getMaxHttpRequestHeaderSize)
.whenNonNull()
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.when(this::isPositive) .when(this::isPositive)
.to((maxHttpRequestHeaderSize) -> factory .to((maxHttpRequestHeaderSize) -> factory
.addServerCustomizers(new MaxHttpRequestHeaderSizeCustomizer(maxHttpRequestHeaderSize))); .addServerCustomizers(new MaxHttpRequestHeaderSizeCustomizer(maxHttpRequestHeaderSize)));
propertyMapper.from(jettyProperties::getMaxHttpResponseHeaderSize) map.from(properties::getMaxHttpResponseHeaderSize)
.whenNonNull()
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.when(this::isPositive) .when(this::isPositive)
.to((maxHttpResponseHeaderSize) -> factory .to((maxHttpResponseHeaderSize) -> factory
.addServerCustomizers(new MaxHttpResponseHeaderSizeCustomizer(maxHttpResponseHeaderSize))); .addServerCustomizers(new MaxHttpResponseHeaderSizeCustomizer(maxHttpResponseHeaderSize)));
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize) map.from(properties::getMaxHttpFormPostSize)
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.when(this::isPositive) .when(this::isPositive)
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize)); .to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
propertyMapper.from(jettyProperties::getConnectionIdleTimeout) map.from(properties::getConnectionIdleTimeout).to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
.whenNonNull() map.from(properties::getAccesslog)
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
propertyMapper.from(jettyProperties::getAccesslog)
.when(ServerProperties.Jetty.Accesslog::isEnabled) .when(ServerProperties.Jetty.Accesslog::isEnabled)
.to((accesslog) -> customizeAccessLog(factory, accesslog)); .to((accesslog) -> customizeAccessLog(factory, accesslog));
} }
@ -251,9 +246,8 @@ public class JettyWebServerFactoryCustomizer
} }
private void customize(ConnectionFactory factory) { private void customize(ConnectionFactory factory) {
if (factory instanceof HttpConfiguration.ConnectionFactory) { if (factory instanceof HttpConfiguration.ConnectionFactory httpConnectionFactory) {
((HttpConfiguration.ConnectionFactory) factory).getHttpConfiguration() httpConnectionFactory.getHttpConfiguration().setResponseHeaderSize(this.maxResponseHeaderSize);
.setResponseHeaderSize(this.maxResponseHeaderSize);
} }
} }

View File

@ -57,17 +57,14 @@ public class NettyWebServerFactoryCustomizer
@Override @Override
public void customize(NettyReactiveWebServerFactory factory) { public void customize(NettyReactiveWebServerFactory factory) {
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders()); factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty(); ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
propertyMapper.from(nettyProperties::getConnectionTimeout) map.from(nettyProperties::getConnectionTimeout)
.whenNonNull()
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout)); .to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
propertyMapper.from(nettyProperties::getIdleTimeout) map.from(nettyProperties::getIdleTimeout).to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
.whenNonNull() map.from(nettyProperties::getMaxKeepAliveRequests)
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
propertyMapper.from(nettyProperties::getMaxKeepAliveRequests)
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests)); .to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
customizeRequestDecoder(factory, propertyMapper); customizeRequestDecoder(factory, map);
} }
private boolean getOrDeduceUseForwardHeaders() { private boolean getOrDeduceUseForwardHeaders() {

View File

@ -83,73 +83,66 @@ public class TomcatWebServerFactoryCustomizer
@Override @Override
public void customize(ConfigurableTomcatWebServerFactory factory) { public void customize(ConfigurableTomcatWebServerFactory factory) {
ServerProperties properties = this.serverProperties; ServerProperties.Tomcat properties = this.serverProperties.getTomcat();
ServerProperties.Tomcat tomcatProperties = properties.getTomcat(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
PropertyMapper propertyMapper = PropertyMapper.get(); map.from(properties::getBasedir).to(factory::setBaseDirectory);
propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory); map.from(properties::getBackgroundProcessorDelay)
propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay)
.whenNonNull()
.as(Duration::getSeconds) .as(Duration::getSeconds)
.as(Long::intValue) .as(Long::intValue)
.to(factory::setBackgroundProcessorDelay); .to(factory::setBackgroundProcessorDelay);
customizeRemoteIpValve(factory); customizeRemoteIpValve(factory);
ServerProperties.Tomcat.Threads threadProperties = tomcatProperties.getThreads(); ServerProperties.Tomcat.Threads threadProperties = properties.getThreads();
propertyMapper.from(threadProperties::getMax) map.from(threadProperties::getMax)
.when(this::isPositive) .when(this::isPositive)
.to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax())); .to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax()));
propertyMapper.from(threadProperties::getMinSpare) map.from(threadProperties::getMinSpare)
.when(this::isPositive) .when(this::isPositive)
.to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads)); .to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
propertyMapper.from(this.serverProperties.getMaxHttpRequestHeaderSize()) map.from(this.serverProperties.getMaxHttpRequestHeaderSize())
.whenNonNull()
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.when(this::isPositive) .when(this::isPositive)
.to((maxHttpRequestHeaderSize) -> customizeMaxHttpRequestHeaderSize(factory, maxHttpRequestHeaderSize)); .to((maxHttpRequestHeaderSize) -> customizeMaxHttpRequestHeaderSize(factory, maxHttpRequestHeaderSize));
propertyMapper.from(tomcatProperties::getMaxHttpResponseHeaderSize) map.from(properties::getMaxHttpResponseHeaderSize)
.whenNonNull()
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.when(this::isPositive) .when(this::isPositive)
.to((maxHttpResponseHeaderSize) -> customizeMaxHttpResponseHeaderSize(factory, maxHttpResponseHeaderSize)); .to((maxHttpResponseHeaderSize) -> customizeMaxHttpResponseHeaderSize(factory, maxHttpResponseHeaderSize));
propertyMapper.from(tomcatProperties::getMaxSwallowSize) map.from(properties::getMaxSwallowSize)
.whenNonNull()
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize)); .to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize) map.from(properties::getMaxHttpFormPostSize)
.asInt(DataSize::toBytes) .asInt(DataSize::toBytes)
.when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0) .when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0)
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize)); .to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
propertyMapper.from(tomcatProperties::getAccesslog) map.from(properties::getAccesslog)
.when(ServerProperties.Tomcat.Accesslog::isEnabled) .when(ServerProperties.Tomcat.Accesslog::isEnabled)
.to((enabled) -> customizeAccessLog(factory)); .to((enabled) -> customizeAccessLog(factory));
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding); map.from(properties::getUriEncoding).to(factory::setUriEncoding);
propertyMapper.from(tomcatProperties::getConnectionTimeout) map.from(properties::getConnectionTimeout)
.whenNonNull()
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout)); .to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
propertyMapper.from(tomcatProperties::getMaxConnections) map.from(properties::getMaxConnections)
.when(this::isPositive) .when(this::isPositive)
.to((maxConnections) -> customizeMaxConnections(factory, maxConnections)); .to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
propertyMapper.from(tomcatProperties::getAcceptCount) map.from(properties::getAcceptCount)
.when(this::isPositive) .when(this::isPositive)
.to((acceptCount) -> customizeAcceptCount(factory, acceptCount)); .to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
propertyMapper.from(tomcatProperties::getProcessorCache) map.from(properties::getProcessorCache)
.to((processorCache) -> customizeProcessorCache(factory, processorCache)); .to((processorCache) -> customizeProcessorCache(factory, processorCache));
propertyMapper.from(tomcatProperties::getKeepAliveTimeout) map.from(properties::getKeepAliveTimeout)
.whenNonNull()
.to((keepAliveTimeout) -> customizeKeepAliveTimeout(factory, keepAliveTimeout)); .to((keepAliveTimeout) -> customizeKeepAliveTimeout(factory, keepAliveTimeout));
propertyMapper.from(tomcatProperties::getMaxKeepAliveRequests) map.from(properties::getMaxKeepAliveRequests)
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests)); .to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
propertyMapper.from(tomcatProperties::getRelaxedPathChars) map.from(properties::getRelaxedPathChars)
.as(this::joinCharacters) .as(this::joinCharacters)
.whenHasText() .whenHasText()
.to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars)); .to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars));
propertyMapper.from(tomcatProperties::getRelaxedQueryChars) map.from(properties::getRelaxedQueryChars)
.as(this::joinCharacters) .as(this::joinCharacters)
.whenHasText() .whenHasText()
.to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars)); .to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
propertyMapper.from(tomcatProperties::isRejectIllegalHeader) map.from(properties::isRejectIllegalHeader)
.to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader)); .to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader));
customizeStaticResources(factory); customizeStaticResources(factory);
customizeErrorReportValve(properties.getError(), factory); customizeErrorReportValve(this.serverProperties.getError(), factory);
} }
private boolean isPositive(int value) { private boolean isPositive(int value) {

View File

@ -87,6 +87,7 @@ public enum CloudPlatform {
/** /**
* Nomad platform. * Nomad platform.
* @since 3.1.0
*/ */
NOMAD { NOMAD {

View File

@ -38,6 +38,7 @@ import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder; import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import ch.qos.logback.core.joran.action.Action; import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ActionException;
import ch.qos.logback.core.joran.spi.ElementSelector; import ch.qos.logback.core.joran.spi.ElementSelector;
import ch.qos.logback.core.joran.spi.RuleStore; import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext; import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
@ -684,27 +685,13 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
mock(BeanFactoryInitializationAotContribution.class)); mock(BeanFactoryInitializationAotContribution.class));
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("joranConfigurator1", new JoranConfigurator() { beanFactory.registerSingleton("joranConfigurator1", new JoranConfigurator() {
@Override @Override
public void addElementSelectorAndActionAssociations(RuleStore ruleStore) { public void addElementSelectorAndActionAssociations(RuleStore ruleStore) {
ruleStore.addRule(new ElementSelector("*/rule1"), () -> new Action() { ruleStore.addRule(new ElementSelector("*/rule1"), () -> new EmptyAction());
@Override ruleStore.addRule(new ElementSelector("*/rule2"), () -> new EmptyAction());
public void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes) {
}
@Override
public void end(SaxEventInterpretationContext intercon, String name) {
}
});
ruleStore.addRule(new ElementSelector("*/rule2"), () -> new Action() {
@Override
public void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes) {
}
@Override
public void end(SaxEventInterpretationContext intercon, String name) {
}
});
} }
}); });
this.loggingSystem.processAheadOfTime(beanFactory); this.loggingSystem.processAheadOfTime(beanFactory);
this.loggingSystem.beforeInitialize(); this.loggingSystem.beforeInitialize();
@ -755,4 +742,17 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
.orElse(null); .orElse(null);
} }
private static class EmptyAction extends Action {
@Override
public void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes)
throws ActionException {
}
@Override
public void end(SaxEventInterpretationContext intercon, String name) throws ActionException {
}
}
} }