Skip to content

Commit e1ce21c

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Closes gh-20499
2 parents 8e7a557 + 2b21137 commit e1ce21c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -131,7 +131,7 @@ public WebServer getWebServer(HttpHandler httpHandler) {
131131
}
132132
TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler);
133133
prepareContext(tomcat.getHost(), servlet);
134-
return new TomcatWebServer(tomcat, getPort() >= 0);
134+
return getTomcatWebServer(tomcat);
135135
}
136136

137137
private void configureEngine(Engine engine) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.net.ServerSocket;
2222
import java.util.Arrays;
2323
import java.util.Map;
24+
import java.util.concurrent.atomic.AtomicReference;
2425

2526
import org.apache.catalina.Context;
2627
import org.apache.catalina.LifecycleEvent;
@@ -256,6 +257,21 @@ void sslWithInvalidAliasFailsDuringStartup() {
256257
.isInstanceOf(WebServerException.class);
257258
}
258259

260+
@Test
261+
void whenGetTomcatWebServerIsOverriddenThenWebServerCreationCanBeCustomized() {
262+
AtomicReference<TomcatWebServer> webServerReference = new AtomicReference<>();
263+
TomcatWebServer webServer = (TomcatWebServer) new TomcatReactiveWebServerFactory() {
264+
265+
@Override
266+
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
267+
webServerReference.set(new TomcatWebServer(tomcat));
268+
return webServerReference.get();
269+
}
270+
271+
}.getWebServer(new EchoHandler());
272+
assertThat(webServerReference).hasValue(webServer);
273+
}
274+
259275
private void doWithBlockedPort(BlockedPortAction action) throws IOException {
260276
int port = SocketUtils.findAvailableTcpPort(40000);
261277
ServerSocket serverSocket = new ServerSocket();

0 commit comments

Comments
 (0)