Skip to content

Commit b20b5ed

Browse files
committed
Polish
1 parent 982e922 commit b20b5ed

File tree

6 files changed

+67
-79
lines changed

6 files changed

+67
-79
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ HazelcastInstance hazelcastInstance(HazelcastProperties properties, ResourceLoad
7777

7878
private Config loadConfig(Resource configLocation) throws IOException {
7979
URL configUrl = configLocation.getURL();
80-
Config config;
81-
try (InputStream stream = configUrl.openStream()) {
82-
config = Config.loadFromStream(stream);
83-
}
80+
Config config = loadConfig(configUrl);
8481
if (ResourceUtils.isFileURL(configUrl)) {
8582
config.setConfigurationFile(configLocation.getFile());
8683
}
@@ -90,6 +87,12 @@ private Config loadConfig(Resource configLocation) throws IOException {
9087
return config;
9188
}
9289

90+
private Config loadConfig(URL configUrl) throws IOException {
91+
try (InputStream stream = configUrl.openStream()) {
92+
return Config.loadFromStream(stream);
93+
}
94+
}
95+
9396
}
9497

9598
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,29 @@ public int getOrder() {
7676

7777
@Override
7878
public void customize(ConfigurableJettyWebServerFactory factory) {
79-
ServerProperties properties = this.serverProperties;
80-
ServerProperties.Jetty jettyProperties = properties.getJetty();
79+
ServerProperties.Jetty properties = this.serverProperties.getJetty();
8180
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
82-
ServerProperties.Jetty.Threads threadProperties = jettyProperties.getThreads();
83-
factory.setThreadPool(determineThreadPool(jettyProperties.getThreads()));
84-
PropertyMapper propertyMapper = PropertyMapper.get();
85-
propertyMapper.from(threadProperties::getAcceptors).whenNonNull().to(factory::setAcceptors);
86-
propertyMapper.from(threadProperties::getSelectors).whenNonNull().to(factory::setSelectors);
87-
propertyMapper.from(properties::getMaxHttpRequestHeaderSize)
88-
.whenNonNull()
81+
ServerProperties.Jetty.Threads threadProperties = properties.getThreads();
82+
factory.setThreadPool(determineThreadPool(properties.getThreads()));
83+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
84+
map.from(threadProperties::getAcceptors).to(factory::setAcceptors);
85+
map.from(threadProperties::getSelectors).to(factory::setSelectors);
86+
map.from(this.serverProperties::getMaxHttpRequestHeaderSize)
8987
.asInt(DataSize::toBytes)
9088
.when(this::isPositive)
9189
.to((maxHttpRequestHeaderSize) -> factory
9290
.addServerCustomizers(new MaxHttpRequestHeaderSizeCustomizer(maxHttpRequestHeaderSize)));
93-
propertyMapper.from(jettyProperties::getMaxHttpResponseHeaderSize)
94-
.whenNonNull()
91+
map.from(properties::getMaxHttpResponseHeaderSize)
9592
.asInt(DataSize::toBytes)
9693
.when(this::isPositive)
9794
.to((maxHttpResponseHeaderSize) -> factory
9895
.addServerCustomizers(new MaxHttpResponseHeaderSizeCustomizer(maxHttpResponseHeaderSize)));
99-
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize)
96+
map.from(properties::getMaxHttpFormPostSize)
10097
.asInt(DataSize::toBytes)
10198
.when(this::isPositive)
10299
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
103-
propertyMapper.from(jettyProperties::getConnectionIdleTimeout)
104-
.whenNonNull()
105-
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
106-
propertyMapper.from(jettyProperties::getAccesslog)
100+
map.from(properties::getConnectionIdleTimeout).to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
101+
map.from(properties::getAccesslog)
107102
.when(ServerProperties.Jetty.Accesslog::isEnabled)
108103
.to((accesslog) -> customizeAccessLog(factory, accesslog));
109104
}
@@ -251,9 +246,8 @@ private void customize(org.eclipse.jetty.server.Connector connector) {
251246
}
252247

253248
private void customize(ConnectionFactory factory) {
254-
if (factory instanceof HttpConfiguration.ConnectionFactory) {
255-
((HttpConfiguration.ConnectionFactory) factory).getHttpConfiguration()
256-
.setResponseHeaderSize(this.maxResponseHeaderSize);
249+
if (factory instanceof HttpConfiguration.ConnectionFactory httpConnectionFactory) {
250+
httpConnectionFactory.getHttpConfiguration().setResponseHeaderSize(this.maxResponseHeaderSize);
257251
}
258252
}
259253

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizer.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,14 @@ public int getOrder() {
5757
@Override
5858
public void customize(NettyReactiveWebServerFactory factory) {
5959
factory.setUseForwardHeaders(getOrDeduceUseForwardHeaders());
60-
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
60+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
6161
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
62-
propertyMapper.from(nettyProperties::getConnectionTimeout)
63-
.whenNonNull()
62+
map.from(nettyProperties::getConnectionTimeout)
6463
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
65-
propertyMapper.from(nettyProperties::getIdleTimeout)
66-
.whenNonNull()
67-
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
68-
propertyMapper.from(nettyProperties::getMaxKeepAliveRequests)
64+
map.from(nettyProperties::getIdleTimeout).to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
65+
map.from(nettyProperties::getMaxKeepAliveRequests)
6966
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
70-
customizeRequestDecoder(factory, propertyMapper);
67+
customizeRequestDecoder(factory, map);
7168
}
7269

7370
private boolean getOrDeduceUseForwardHeaders() {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,73 +83,66 @@ public int getOrder() {
8383

8484
@Override
8585
public void customize(ConfigurableTomcatWebServerFactory factory) {
86-
ServerProperties properties = this.serverProperties;
87-
ServerProperties.Tomcat tomcatProperties = properties.getTomcat();
88-
PropertyMapper propertyMapper = PropertyMapper.get();
89-
propertyMapper.from(tomcatProperties::getBasedir).whenNonNull().to(factory::setBaseDirectory);
90-
propertyMapper.from(tomcatProperties::getBackgroundProcessorDelay)
91-
.whenNonNull()
86+
ServerProperties.Tomcat properties = this.serverProperties.getTomcat();
87+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
88+
map.from(properties::getBasedir).to(factory::setBaseDirectory);
89+
map.from(properties::getBackgroundProcessorDelay)
9290
.as(Duration::getSeconds)
9391
.as(Long::intValue)
9492
.to(factory::setBackgroundProcessorDelay);
9593
customizeRemoteIpValve(factory);
96-
ServerProperties.Tomcat.Threads threadProperties = tomcatProperties.getThreads();
97-
propertyMapper.from(threadProperties::getMax)
94+
ServerProperties.Tomcat.Threads threadProperties = properties.getThreads();
95+
map.from(threadProperties::getMax)
9896
.when(this::isPositive)
9997
.to((maxThreads) -> customizeMaxThreads(factory, threadProperties.getMax()));
100-
propertyMapper.from(threadProperties::getMinSpare)
98+
map.from(threadProperties::getMinSpare)
10199
.when(this::isPositive)
102100
.to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
103-
propertyMapper.from(this.serverProperties.getMaxHttpRequestHeaderSize())
104-
.whenNonNull()
101+
map.from(this.serverProperties.getMaxHttpRequestHeaderSize())
105102
.asInt(DataSize::toBytes)
106103
.when(this::isPositive)
107104
.to((maxHttpRequestHeaderSize) -> customizeMaxHttpRequestHeaderSize(factory, maxHttpRequestHeaderSize));
108-
propertyMapper.from(tomcatProperties::getMaxHttpResponseHeaderSize)
109-
.whenNonNull()
105+
map.from(properties::getMaxHttpResponseHeaderSize)
110106
.asInt(DataSize::toBytes)
111107
.when(this::isPositive)
112108
.to((maxHttpResponseHeaderSize) -> customizeMaxHttpResponseHeaderSize(factory, maxHttpResponseHeaderSize));
113-
propertyMapper.from(tomcatProperties::getMaxSwallowSize)
114-
.whenNonNull()
109+
map.from(properties::getMaxSwallowSize)
115110
.asInt(DataSize::toBytes)
116111
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
117-
propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize)
112+
map.from(properties::getMaxHttpFormPostSize)
118113
.asInt(DataSize::toBytes)
119114
.when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0)
120115
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
121-
propertyMapper.from(tomcatProperties::getAccesslog)
116+
map.from(properties::getAccesslog)
122117
.when(ServerProperties.Tomcat.Accesslog::isEnabled)
123118
.to((enabled) -> customizeAccessLog(factory));
124-
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
125-
propertyMapper.from(tomcatProperties::getConnectionTimeout)
126-
.whenNonNull()
119+
map.from(properties::getUriEncoding).to(factory::setUriEncoding);
120+
map.from(properties::getConnectionTimeout)
127121
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
128-
propertyMapper.from(tomcatProperties::getMaxConnections)
122+
map.from(properties::getMaxConnections)
129123
.when(this::isPositive)
130124
.to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
131-
propertyMapper.from(tomcatProperties::getAcceptCount)
125+
map.from(properties::getAcceptCount)
132126
.when(this::isPositive)
133127
.to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
134-
propertyMapper.from(tomcatProperties::getProcessorCache)
128+
map.from(properties::getProcessorCache)
135129
.to((processorCache) -> customizeProcessorCache(factory, processorCache));
136-
propertyMapper.from(tomcatProperties::getKeepAliveTimeout)
137-
.whenNonNull()
130+
map.from(properties::getKeepAliveTimeout)
138131
.to((keepAliveTimeout) -> customizeKeepAliveTimeout(factory, keepAliveTimeout));
139-
propertyMapper.from(tomcatProperties::getMaxKeepAliveRequests)
132+
map.from(properties::getMaxKeepAliveRequests)
140133
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
141-
propertyMapper.from(tomcatProperties::getRelaxedPathChars)
134+
map.from(properties::getRelaxedPathChars)
142135
.as(this::joinCharacters)
143136
.whenHasText()
144137
.to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars));
145-
propertyMapper.from(tomcatProperties::getRelaxedQueryChars)
138+
map.from(properties::getRelaxedQueryChars)
146139
.as(this::joinCharacters)
147140
.whenHasText()
148141
.to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
149-
propertyMapper.from(tomcatProperties::isRejectIllegalHeader)
142+
map.from(properties::isRejectIllegalHeader)
150143
.to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader));
151144
customizeStaticResources(factory);
152-
customizeErrorReportValve(properties.getError(), factory);
145+
customizeErrorReportValve(this.serverProperties.getError(), factory);
153146
}
154147

155148
private boolean isPositive(int value) {

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public boolean isDetected(Environment environment) {
8787

8888
/**
8989
* Nomad platform.
90+
* @since 3.1.0
9091
*/
9192
NOMAD {
9293

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import ch.qos.logback.core.ConsoleAppender;
3939
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
4040
import ch.qos.logback.core.joran.action.Action;
41+
import ch.qos.logback.core.joran.spi.ActionException;
4142
import ch.qos.logback.core.joran.spi.ElementSelector;
4243
import ch.qos.logback.core.joran.spi.RuleStore;
4344
import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
@@ -684,27 +685,13 @@ void whenContextHasConfiguratorsThenInitializeExecutesThem(CapturedOutput output
684685
mock(BeanFactoryInitializationAotContribution.class));
685686
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
686687
beanFactory.registerSingleton("joranConfigurator1", new JoranConfigurator() {
688+
687689
@Override
688690
public void addElementSelectorAndActionAssociations(RuleStore ruleStore) {
689-
ruleStore.addRule(new ElementSelector("*/rule1"), () -> new Action() {
690-
@Override
691-
public void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes) {
692-
}
693-
694-
@Override
695-
public void end(SaxEventInterpretationContext intercon, String name) {
696-
}
697-
});
698-
ruleStore.addRule(new ElementSelector("*/rule2"), () -> new Action() {
699-
@Override
700-
public void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes) {
701-
}
702-
703-
@Override
704-
public void end(SaxEventInterpretationContext intercon, String name) {
705-
}
706-
});
691+
ruleStore.addRule(new ElementSelector("*/rule1"), () -> new EmptyAction());
692+
ruleStore.addRule(new ElementSelector("*/rule2"), () -> new EmptyAction());
707693
}
694+
708695
});
709696
this.loggingSystem.processAheadOfTime(beanFactory);
710697
this.loggingSystem.beforeInitialize();
@@ -755,4 +742,17 @@ private String getLineWithText(CharSequence output, CharSequence outputSearch) {
755742
.orElse(null);
756743
}
757744

745+
private static class EmptyAction extends Action {
746+
747+
@Override
748+
public void begin(SaxEventInterpretationContext intercon, String name, Attributes attributes)
749+
throws ActionException {
750+
}
751+
752+
@Override
753+
public void end(SaxEventInterpretationContext intercon, String name) throws ActionException {
754+
}
755+
756+
}
757+
758758
}

0 commit comments

Comments
 (0)