Merge branch '2.1.x' into 2.2.x

Closes gh-20499
pull/20523/head
Andy Wilkinson 5 years ago
commit e1ce21c3a5

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -131,7 +131,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
} }
TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler); TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler);
prepareContext(tomcat.getHost(), servlet); prepareContext(tomcat.getHost(), servlet);
return new TomcatWebServer(tomcat, getPort() >= 0); return getTomcatWebServer(tomcat);
} }
private void configureEngine(Engine engine) { private void configureEngine(Engine engine) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2020 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.catalina.Context; import org.apache.catalina.Context;
import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleEvent;
@ -256,6 +257,21 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
.isInstanceOf(WebServerException.class); .isInstanceOf(WebServerException.class);
} }
@Test
void whenGetTomcatWebServerIsOverriddenThenWebServerCreationCanBeCustomized() {
AtomicReference<TomcatWebServer> webServerReference = new AtomicReference<>();
TomcatWebServer webServer = (TomcatWebServer) new TomcatReactiveWebServerFactory() {
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
webServerReference.set(new TomcatWebServer(tomcat));
return webServerReference.get();
}
}.getWebServer(new EchoHandler());
assertThat(webServerReference).hasValue(webServer);
}
private void doWithBlockedPort(BlockedPortAction action) throws IOException { private void doWithBlockedPort(BlockedPortAction action) throws IOException {
int port = SocketUtils.findAvailableTcpPort(40000); int port = SocketUtils.findAvailableTcpPort(40000);
ServerSocket serverSocket = new ServerSocket(); ServerSocket serverSocket = new ServerSocket();

Loading…
Cancel
Save