Skip to content

Commit 427d262

Browse files
committed
Polish
1 parent a0580da commit 427d262

File tree

19 files changed

+140
-140
lines changed

19 files changed

+140
-140
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,9 @@ protected RequestPredicate acceptsTextHtml() {
193193
*/
194194
protected void logError(ServerRequest request, HttpStatus errorStatus) {
195195
if (errorStatus.is5xxServerError()) {
196-
Throwable error = getError(request);
197-
final String message = "Failed to handle request ["
198-
+ request.methodName() + " " + request.uri() + "]";
199-
logger.error(message, error);
196+
Throwable ex = getError(request);
197+
logger.error("Failed to handle request [" + request.methodName() + " "
198+
+ request.uri() + "]", ex);
200199
}
201200
}
202201

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ content into your application; rather pick only the properties that you need.
165165
server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
166166
server.error.path=/error # Path of the error controller.
167167
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
168-
server.http2.enabled=true # Enable HTTP/2 support if the current environment supports it.
168+
server.http2.enabled=true # Whether to enable HTTP/2 support, if the current environment supports it.
169169
server.jetty.acceptors= # Number of acceptor threads to use.
170170
server.jetty.accesslog.append=false # Append to log.
171171
server.jetty.accesslog.date-format=dd/MMM/yyyy:HH:mm:ss Z # Timestamp format of the request log.

spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -737,50 +737,51 @@ sample project for an example.
737737
[[howto-configure-http2]]
738738
=== Configure HTTP/2
739739
You can enable HTTP/2 support in your Spring Boot application with the
740-
`+server.http2.enabled+` configuration property. This support depends on the
741-
chosen web server and the application environment, since that protocol is not
742-
supported out-of-the-box by JDK8.
740+
`+server.http2.enabled+` configuration property. This support depends on the chosen web
741+
server and the application environment, since that protocol is not supported
742+
out-of-the-box by JDK8.
743743

744744
[NOTE]
745745
====
746-
Spring Boot does not support `h2c`, the cleartext version of the HTTP/2
747-
protocol. So you must configure <<howto-configure-ssl, configure SSL first>>.
746+
Spring Boot does not support `h2c`, the cleartext version of the HTTP/2 protocol. So you
747+
must configure <<howto-configure-ssl, configure SSL first>>.
748748
====
749749

750750
Currently, only Undertow and Tomcat are supported with this configuration key.
751751

752752

753+
753754
[[howto-configure-http2-undertow]]
754755
==== HTTP/2 with Undertow
755-
As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement
756-
on JDK8.
756+
As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement on JDK8.
757+
757758

758759

759760
[[howto-configure-http2-tomcat]]
760761
==== HTTP/2 with Tomcat
761-
Spring Boot ships by default with Tomcat 8.5.x; with that version,
762-
HTTP/2 is only supported if the `libtcnative` library and its dependencies
763-
are installed on the host operating system.
762+
Spring Boot ships by default with Tomcat 8.5.x; with that version, HTTP/2 is only
763+
supported if the `libtcnative` library and its dependencies are installed on the host
764+
operating system.
764765

765-
The library folder must be made available, if not already, to the JVM library
766-
path; this can be done with a JVM argument such as
766+
The library folder must be made available, if not already, to the JVM library path; this
767+
can be done with a JVM argument such as
767768
`-Djava.library.path=/usr/local/opt/tomcat-native/lib`. More on this in the
768-
http://tomcat.apache.org/tomcat-8.5-doc/apr.html[official Tomcat
769-
documentation].
769+
http://tomcat.apache.org/tomcat-8.5-doc/apr.html[official Tomcat documentation].
770770

771771
Starting Tomcat 8.5.x without that native support will log the following error:
772772

773773
[indent=0,subs="attributes"]
774774
----
775-
ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
775+
ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
776776
----
777777

778-
This error is not fatal, and the application starts with HTTP/1.1 SSL
779-
support still.
778+
This error is not fatal, and the application starts with HTTP/1.1 SSL support still.
779+
780+
Running your application with Tomcat 9.0.x and JDK9 doesn't require any native library
781+
installed. To use Tomcat 9, you can override the `tomcat.version` build property with the
782+
version of your choice.
783+
780784

781-
Running your application with Tomcat 9.0.x and JDK9 doesn't require any native
782-
library installed. To use Tomcat 9, you can override the `tomcat.version`
783-
build property with the version of your choice.
784785

785786
[[howto-configure-accesslogs]]
786787
=== Configure Access Logging

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ protected Server createJettyServer(JettyHttpHandlerAdapter servlet) {
9797
ServletContextHandler contextHandler = new ServletContextHandler(server, "",
9898
false, false);
9999
contextHandler.addServlet(servletHolder, "/");
100-
this.logger.info("Server initialized with port: " + port);
101-
SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(port,
102-
getSsl(), getSslStoreProvider());
103-
sslServerCustomizer.customize(server);
100+
JettyReactiveWebServerFactory.logger
101+
.info("Server initialized with port: " + port);
102+
new SslServerCustomizer(port, getSsl(), getSslStoreProvider()).customize(server);
104103
for (JettyServerCustomizer customizer : getServerCustomizers()) {
105104
customizer.customize(server);
106105
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
153153
configureWebAppContext(context, initializers);
154154
server.setHandler(addHandlerWrappers(context));
155155
this.logger.info("Server initialized with port: " + port);
156-
SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(port,
157-
getSsl(), getSslStoreProvider());
158-
sslServerCustomizer.customize(server);
156+
new SslServerCustomizer(port, getSsl(), getSslStoreProvider()).customize(server);
159157
for (JettyServerCustomizer customizer : getServerCustomizers()) {
160158
customizer.customize(server);
161159
}
@@ -167,7 +165,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
167165

168166
private Server createServer(InetSocketAddress address) {
169167
Server server = new Server(getThreadPool());
170-
server.setConnectors(new Connector[] {createConnector(address, server)});
168+
server.setConnectors(new Connector[] { createConnector(address, server) });
171169
return server;
172170
}
173171

@@ -338,7 +336,7 @@ protected final void addJspServlet(WebAppContext context) {
338336
context.getServletHandler().addServlet(holder);
339337
ServletMapping mapping = new ServletMapping();
340338
mapping.setServletName("jsp");
341-
mapping.setPathSpecs(new String[] {"*.jsp", "*.jspx"});
339+
mapping.setPathSpecs(new String[] { "*.jsp", "*.jspx" });
342340
context.getServletHandler().addServletMapping(mapping);
343341
}
344342

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import org.springframework.util.ResourceUtils;
3939

4040
/**
41-
* {@link JettyServerCustomizer} that configures SSL on the
42-
* given Jetty server instance.
41+
* {@link JettyServerCustomizer} that configures SSL on the given Jetty server instance.
4342
*
4443
* @author Brian Clozel
4544
*/
@@ -88,7 +87,8 @@ private AbstractConnector createSslConnector(Server server,
8887
* @param ssl the ssl details.
8988
* @param sslStoreProvider the ssl store provider
9089
*/
91-
protected void configureSsl(SslContextFactory factory, Ssl ssl, SslStoreProvider sslStoreProvider) {
90+
protected void configureSsl(SslContextFactory factory, Ssl ssl,
91+
SslStoreProvider sslStoreProvider) {
9292
factory.setProtocol(ssl.getProtocol());
9393
configureSslClientAuth(factory, ssl);
9494
configureSslPasswords(factory, ssl);
@@ -172,4 +172,5 @@ private void configureSslTrustStore(SslContextFactory factory, Ssl ssl) {
172172
factory.setTrustStoreProvider(ssl.getTrustStoreProvider());
173173
}
174174
}
175+
175176
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/CompressionConnectorCustomizer.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
import org.springframework.util.StringUtils;
2525

2626
/**
27-
* {@link TomcatConnectorCustomizer} that configures compression
28-
* support on the given Connector.
27+
* {@link TomcatConnectorCustomizer} that configures compression support on the given
28+
* Connector.
2929
*
3030
* @author Brian Clozel
3131
*/
3232
class CompressionConnectorCustomizer implements TomcatConnectorCustomizer {
3333

34-
3534
private final Compression compression;
3635

3736
CompressionConnectorCustomizer(Compression compression) {
@@ -43,18 +42,21 @@ public void customize(Connector connector) {
4342
if (this.compression != null && this.compression.getEnabled()) {
4443
ProtocolHandler handler = connector.getProtocolHandler();
4544
if (handler instanceof AbstractHttp11Protocol) {
46-
AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
47-
Compression compression = this.compression;
48-
protocol.setCompression("on");
49-
protocol.setCompressionMinSize(compression.getMinResponseSize());
50-
protocol.setCompressibleMimeType(
51-
StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes()));
52-
if (this.compression.getExcludedUserAgents() != null) {
53-
protocol.setNoCompressionUserAgents(
54-
StringUtils.arrayToCommaDelimitedString(
55-
this.compression.getExcludedUserAgents()));
56-
}
45+
customize((AbstractHttp11Protocol<?>) handler);
5746
}
5847
}
5948
}
49+
50+
private void customize(AbstractHttp11Protocol<?> protocol) {
51+
Compression compression = this.compression;
52+
protocol.setCompression("on");
53+
protocol.setCompressionMinSize(compression.getMinResponseSize());
54+
protocol.setCompressibleMimeType(
55+
StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes()));
56+
if (this.compression.getExcludedUserAgents() != null) {
57+
protocol.setNoCompressionUserAgents(StringUtils.arrayToCommaDelimitedString(
58+
this.compression.getExcludedUserAgents()));
59+
}
60+
}
61+
6062
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizer.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
import org.springframework.util.StringUtils;
3434

3535
/**
36-
* {@link TomcatConnectorCustomizer} that configures SSL support
37-
* on the given connector.
36+
* {@link TomcatConnectorCustomizer} that configures SSL support on the given connector.
3837
*
3938
* @author Brian Clozel
4039
*/
@@ -56,8 +55,8 @@ public void customize(Connector connector) {
5655
Assert.state(handler instanceof AbstractHttp11JsseProtocol,
5756
"To use SSL, the connector's protocol handler must be an "
5857
+ "AbstractHttp11JsseProtocol subclass");
59-
configureSsl((AbstractHttp11JsseProtocol<?>) handler,
60-
this.ssl, this.sslStoreProvider);
58+
configureSsl((AbstractHttp11JsseProtocol<?>) handler, this.ssl,
59+
this.sslStoreProvider);
6160
connector.setScheme("https");
6261
connector.setSecure(true);
6362
}
@@ -68,8 +67,8 @@ public void customize(Connector connector) {
6867
* @param ssl the ssl details
6968
* @param sslStoreProvider the ssl store provider
7069
*/
71-
protected void configureSsl(AbstractHttp11JsseProtocol<?> protocol,
72-
Ssl ssl, SslStoreProvider sslStoreProvider) {
70+
protected void configureSsl(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl,
71+
SslStoreProvider sslStoreProvider) {
7372
protocol.setSSLEnabled(true);
7473
protocol.setSslProtocol(ssl.getProtocol());
7574
configureSslClientAuth(protocol, ssl);
@@ -112,8 +111,7 @@ protected void configureSslStoreProvider(AbstractHttp11JsseProtocol<?> protocol,
112111
.getInstance();
113112
instance.addUserFactory(
114113
new SslStoreProviderUrlStreamHandlerFactory(sslStoreProvider));
115-
protocol.setKeystoreFile(
116-
SslStoreProviderUrlStreamHandlerFactory.KEY_STORE_URL);
114+
protocol.setKeystoreFile(SslStoreProviderUrlStreamHandlerFactory.KEY_STORE_URL);
117115
protocol.setTruststoreFile(
118116
SslStoreProviderUrlStreamHandlerFactory.TRUST_STORE_URL);
119117
}
@@ -153,4 +151,5 @@ private void configureSslTrustStore(AbstractHttp11JsseProtocol<?> protocol, Ssl
153151
protocol.setTruststoreProvider(ssl.getTrustStoreProvider());
154152
}
155153
}
154+
156155
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Collection;
23+
import java.util.Collections;
2324
import java.util.List;
2425

2526
import org.apache.catalina.Context;
@@ -56,7 +57,8 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
5657

5758
private String protocol = DEFAULT_PROTOCOL;
5859

59-
private List<LifecycleListener> contextLifecycleListeners = Arrays.asList(new AprLifecycleListener());
60+
private List<LifecycleListener> contextLifecycleListeners = new ArrayList<LifecycleListener>(
61+
Collections.singleton(new AprLifecycleListener()));
6062

6163
private List<TomcatContextCustomizer> tomcatContextCustomizers = new ArrayList<>();
6264

@@ -120,15 +122,11 @@ protected void prepareContext(Host host, TomcatHttpHandlerAdapter servlet) {
120122
* @param context the Tomcat context
121123
*/
122124
protected void configureContext(Context context) {
123-
for (LifecycleListener lifecycleListener : this.contextLifecycleListeners) {
124-
context.addLifecycleListener(lifecycleListener);
125-
}
126-
for (TomcatContextCustomizer customizer : this.tomcatContextCustomizers) {
127-
customizer.customize(context);
128-
}
125+
this.contextLifecycleListeners.forEach(context::addLifecycleListener);
126+
this.tomcatContextCustomizers
127+
.forEach((customizer) -> customizer.customize(context));
129128
}
130129

131-
// Needs to be protected so it can be used by subclasses
132130
protected void customizeConnector(Connector connector) {
133131
int port = (getPort() >= 0 ? getPort() : 0);
134132
connector.setPort(port);
@@ -138,18 +136,13 @@ protected void customizeConnector(Connector connector) {
138136
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
139137
customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler());
140138
}
141-
142-
// If ApplicationContext is slow to start we want Tomcat not to bind to the socket
143-
// prematurely...
139+
// Don't bind to the socket prematurely if ApplicationContext is slow to start
144140
connector.setProperty("bindOnInit", "false");
145141
if (getSsl() != null && getSsl().isEnabled()) {
146-
TomcatConnectorCustomizer ssl = new SslConnectorCustomizer(getSsl(), getSslStoreProvider());
147-
ssl.customize(connector);
148-
if (getHttp2() != null && getHttp2().getEnabled()) {
149-
connector.addUpgradeProtocol(new Http2Protocol());
150-
}
142+
customizeSsl(connector);
151143
}
152-
TomcatConnectorCustomizer compression = new CompressionConnectorCustomizer(getCompression());
144+
TomcatConnectorCustomizer compression = new CompressionConnectorCustomizer(
145+
getCompression());
153146
compression.customize(connector);
154147
for (TomcatConnectorCustomizer customizer : this.tomcatConnectorCustomizers) {
155148
customizer.customize(connector);
@@ -162,6 +155,13 @@ private void customizeProtocol(AbstractProtocol<?> protocol) {
162155
}
163156
}
164157

158+
private void customizeSsl(Connector connector) {
159+
new SslConnectorCustomizer(getSsl(), getSslStoreProvider()).customize(connector);
160+
if (getHttp2() != null && getHttp2().getEnabled()) {
161+
connector.addUpgradeProtocol(new Http2Protocol());
162+
}
163+
}
164+
165165
/**
166166
* Set {@link TomcatContextCustomizer}s that should be applied to the Tomcat
167167
* {@link Context} . Calling this method will replace any existing customizers.
@@ -260,7 +260,6 @@ public void addContextLifecycleListeners(
260260
this.contextLifecycleListeners.addAll(Arrays.asList(contextLifecycleListeners));
261261
}
262262

263-
264263
/**
265264
* Factory method called to create the {@link TomcatWebServer}. Subclasses can
266265
* override this method to return a different {@link TomcatWebServer} or apply

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
111111

112112
private List<Valve> contextValves = new ArrayList<>();
113113

114-
private List<LifecycleListener> contextLifecycleListeners = Arrays.asList(new AprLifecycleListener());
114+
private List<LifecycleListener> contextLifecycleListeners = new ArrayList<>(
115+
Collections.singleton(new AprLifecycleListener()));
115116

116117
private List<TomcatContextCustomizer> tomcatContextCustomizers = new ArrayList<>();
117118

@@ -293,19 +294,13 @@ protected void customizeConnector(Connector connector) {
293294
if (getUriEncoding() != null) {
294295
connector.setURIEncoding(getUriEncoding().name());
295296
}
296-
297-
// If ApplicationContext is slow to start we want Tomcat not to bind to the socket
298-
// prematurely...
297+
// Don't bind to the socket prematurely if ApplicationContext is slow to start
299298
connector.setProperty("bindOnInit", "false");
300-
301299
if (getSsl() != null && getSsl().isEnabled()) {
302-
TomcatConnectorCustomizer ssl = new SslConnectorCustomizer(getSsl(), getSslStoreProvider());
303-
ssl.customize(connector);
304-
if (getHttp2() != null && getHttp2().getEnabled()) {
305-
connector.addUpgradeProtocol(new Http2Protocol());
306-
}
300+
customizeSsl(connector);
307301
}
308-
TomcatConnectorCustomizer compression = new CompressionConnectorCustomizer(getCompression());
302+
TomcatConnectorCustomizer compression = new CompressionConnectorCustomizer(
303+
getCompression());
309304
compression.customize(connector);
310305
for (TomcatConnectorCustomizer customizer : this.tomcatConnectorCustomizers) {
311306
customizer.customize(connector);
@@ -318,6 +313,13 @@ private void customizeProtocol(AbstractProtocol<?> protocol) {
318313
}
319314
}
320315

316+
private void customizeSsl(Connector connector) {
317+
new SslConnectorCustomizer(getSsl(), getSslStoreProvider()).customize(connector);
318+
if (getHttp2() != null && getHttp2().getEnabled()) {
319+
connector.addUpgradeProtocol(new Http2Protocol());
320+
}
321+
}
322+
321323
/**
322324
* Configure the Tomcat {@link Context}.
323325
* @param context the Tomcat context

0 commit comments

Comments
 (0)