Closes gh-16597
pull/16611/head
Johnny Lim 6 years ago committed by Stephane Nicoll
parent b879972d0d
commit 62549ffb49

@ -172,7 +172,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler());
}
invokeProtocolHandlerCustomizers(connector);
invokeProtocolHandlerCustomizers(connector.getProtocolHandler());
if (getUriEncoding() != null) {
connector.setURIEncoding(getUriEncoding().name());
}
@ -190,8 +190,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
}
@SuppressWarnings("unchecked")
private void invokeProtocolHandlerCustomizers(Connector connector) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
private void invokeProtocolHandlerCustomizers(ProtocolHandler protocolHandler) {
LambdaSafe
.callbacks(TomcatProtocolHandlerCustomizer.class,
this.tomcatProtocolHandlerCustomizers, protocolHandler)

@ -307,7 +307,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler());
}
invokeProtocolHandlerCustomizers(connector);
invokeProtocolHandlerCustomizers(connector.getProtocolHandler());
if (getUriEncoding() != null) {
connector.setURIEncoding(getUriEncoding().name());
}
@ -331,8 +331,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
}
@SuppressWarnings("unchecked")
private void invokeProtocolHandlerCustomizers(Connector connector) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
private void invokeProtocolHandlerCustomizers(ProtocolHandler protocolHandler) {
LambdaSafe
.callbacks(TomcatProtocolHandlerCustomizer.class,
this.tomcatProtocolHandlerCustomizers, protocolHandler)

@ -59,14 +59,15 @@ public class TomcatReactiveWebServerFactoryTests
@Test
public void tomcatCustomizers() {
TomcatReactiveWebServerFactory factory = getFactory();
TomcatContextCustomizer[] listeners = new TomcatContextCustomizer[4];
Arrays.setAll(listeners, (i) -> mock(TomcatContextCustomizer.class));
factory.setTomcatContextCustomizers(Arrays.asList(listeners[0], listeners[1]));
factory.addContextCustomizers(listeners[2], listeners[3]);
TomcatContextCustomizer[] customizers = new TomcatContextCustomizer[4];
Arrays.setAll(customizers, (i) -> mock(TomcatContextCustomizer.class));
factory.setTomcatContextCustomizers(
Arrays.asList(customizers[0], customizers[1]));
factory.addContextCustomizers(customizers[2], customizers[3]);
this.webServer = factory.getWebServer(mock(HttpHandler.class));
InOrder ordered = inOrder((Object[]) listeners);
for (TomcatContextCustomizer listener : listeners) {
ordered.verify(listener).customize(any(Context.class));
InOrder ordered = inOrder((Object[]) customizers);
for (TomcatContextCustomizer customizer : customizers) {
ordered.verify(customizer).customize(any(Context.class));
}
}
@ -145,14 +146,15 @@ public class TomcatReactiveWebServerFactoryTests
public void tomcatConnectorCustomizersShouldBeInvoked() {
TomcatReactiveWebServerFactory factory = getFactory();
HttpHandler handler = mock(HttpHandler.class);
TomcatConnectorCustomizer[] listeners = new TomcatConnectorCustomizer[4];
Arrays.setAll(listeners, (i) -> mock(TomcatConnectorCustomizer.class));
factory.setTomcatConnectorCustomizers(Arrays.asList(listeners[0], listeners[1]));
factory.addConnectorCustomizers(listeners[2], listeners[3]);
TomcatConnectorCustomizer[] customizers = new TomcatConnectorCustomizer[4];
Arrays.setAll(customizers, (i) -> mock(TomcatConnectorCustomizer.class));
factory.setTomcatConnectorCustomizers(
Arrays.asList(customizers[0], customizers[1]));
factory.addConnectorCustomizers(customizers[2], customizers[3]);
this.webServer = factory.getWebServer(handler);
InOrder ordered = inOrder((Object[]) listeners);
for (TomcatConnectorCustomizer listener : listeners) {
ordered.verify(listener).customize(any(Connector.class));
InOrder ordered = inOrder((Object[]) customizers);
for (TomcatConnectorCustomizer customizer : customizers) {
ordered.verify(customizer).customize(any(Connector.class));
}
}
@ -160,15 +162,15 @@ public class TomcatReactiveWebServerFactoryTests
public void tomcatProtocolHandlerCustomizersShouldBeInvoked() {
TomcatReactiveWebServerFactory factory = getFactory();
HttpHandler handler = mock(HttpHandler.class);
TomcatProtocolHandlerCustomizer<AbstractHttp11Protocol>[] listeners = new TomcatProtocolHandlerCustomizer[4];
Arrays.setAll(listeners, (i) -> mock(TomcatProtocolHandlerCustomizer.class));
TomcatProtocolHandlerCustomizer<AbstractHttp11Protocol>[] customizers = new TomcatProtocolHandlerCustomizer[4];
Arrays.setAll(customizers, (i) -> mock(TomcatProtocolHandlerCustomizer.class));
factory.setTomcatProtocolHandlerCustomizers(
Arrays.asList(listeners[0], listeners[1]));
factory.addProtocolHandlerCustomizers(listeners[2], listeners[3]);
Arrays.asList(customizers[0], customizers[1]));
factory.addProtocolHandlerCustomizers(customizers[2], customizers[3]);
this.webServer = factory.getWebServer(handler);
InOrder ordered = inOrder((Object[]) listeners);
for (TomcatProtocolHandlerCustomizer listener : listeners) {
ordered.verify(listener).customize(any(ProtocolHandler.class));
InOrder ordered = inOrder((Object[]) customizers);
for (TomcatProtocolHandlerCustomizer customizer : customizers) {
ordered.verify(customizer).customize(any(ProtocolHandler.class));
}
}

@ -162,14 +162,15 @@ public class TomcatServletWebServerFactoryTests
@Test
public void tomcatCustomizers() {
TomcatServletWebServerFactory factory = getFactory();
TomcatContextCustomizer[] listeners = new TomcatContextCustomizer[4];
Arrays.setAll(listeners, (i) -> mock(TomcatContextCustomizer.class));
factory.setTomcatContextCustomizers(Arrays.asList(listeners[0], listeners[1]));
factory.addContextCustomizers(listeners[2], listeners[3]);
TomcatContextCustomizer[] customizers = new TomcatContextCustomizer[4];
Arrays.setAll(customizers, (i) -> mock(TomcatContextCustomizer.class));
factory.setTomcatContextCustomizers(
Arrays.asList(customizers[0], customizers[1]));
factory.addContextCustomizers(customizers[2], customizers[3]);
this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) listeners);
for (TomcatContextCustomizer listener : listeners) {
ordered.verify(listener).customize(any(Context.class));
InOrder ordered = inOrder((Object[]) customizers);
for (TomcatContextCustomizer customizer : customizers) {
ordered.verify(customizer).customize(any(Context.class));
}
}
@ -187,29 +188,30 @@ public class TomcatServletWebServerFactoryTests
@Test
public void tomcatConnectorCustomizers() {
TomcatServletWebServerFactory factory = getFactory();
TomcatConnectorCustomizer[] listeners = new TomcatConnectorCustomizer[4];
Arrays.setAll(listeners, (i) -> mock(TomcatConnectorCustomizer.class));
factory.setTomcatConnectorCustomizers(Arrays.asList(listeners[0], listeners[1]));
factory.addConnectorCustomizers(listeners[2], listeners[3]);
TomcatConnectorCustomizer[] customizers = new TomcatConnectorCustomizer[4];
Arrays.setAll(customizers, (i) -> mock(TomcatConnectorCustomizer.class));
factory.setTomcatConnectorCustomizers(
Arrays.asList(customizers[0], customizers[1]));
factory.addConnectorCustomizers(customizers[2], customizers[3]);
this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) listeners);
for (TomcatConnectorCustomizer listener : listeners) {
ordered.verify(listener).customize(any(Connector.class));
InOrder ordered = inOrder((Object[]) customizers);
for (TomcatConnectorCustomizer customizer : customizers) {
ordered.verify(customizer).customize(any(Connector.class));
}
}
@Test
public void tomcatProtocolHandlerCustomizersShouldBeInvoked() {
TomcatServletWebServerFactory factory = getFactory();
TomcatProtocolHandlerCustomizer<AbstractHttp11Protocol>[] listeners = new TomcatProtocolHandlerCustomizer[4];
Arrays.setAll(listeners, (i) -> mock(TomcatProtocolHandlerCustomizer.class));
TomcatProtocolHandlerCustomizer<AbstractHttp11Protocol>[] customizers = new TomcatProtocolHandlerCustomizer[4];
Arrays.setAll(customizers, (i) -> mock(TomcatProtocolHandlerCustomizer.class));
factory.setTomcatProtocolHandlerCustomizers(
Arrays.asList(listeners[0], listeners[1]));
factory.addProtocolHandlerCustomizers(listeners[2], listeners[3]);
Arrays.asList(customizers[0], customizers[1]));
factory.addProtocolHandlerCustomizers(customizers[2], customizers[3]);
this.webServer = factory.getWebServer();
InOrder ordered = inOrder((Object[]) listeners);
for (TomcatProtocolHandlerCustomizer listener : listeners) {
ordered.verify(listener).customize(any(ProtocolHandler.class));
InOrder ordered = inOrder((Object[]) customizers);
for (TomcatProtocolHandlerCustomizer customizer : customizers) {
ordered.verify(customizer).customize(any(ProtocolHandler.class));
}
}
@ -230,14 +232,14 @@ public class TomcatServletWebServerFactoryTests
@Test
public void tomcatAdditionalConnectors() {
TomcatServletWebServerFactory factory = getFactory();
Connector[] listeners = new Connector[4];
Arrays.setAll(listeners, (i) -> new Connector());
factory.addAdditionalTomcatConnectors(listeners);
Connector[] connectors = new Connector[4];
Arrays.setAll(connectors, (i) -> new Connector());
factory.addAdditionalTomcatConnectors(connectors);
this.webServer = factory.getWebServer();
Map<Service, Connector[]> connectors = ((TomcatWebServer) this.webServer)
Map<Service, Connector[]> connectorsByService = ((TomcatWebServer) this.webServer)
.getServiceConnectors();
assertThat(connectors.values().iterator().next().length)
.isEqualTo(listeners.length + 1);
assertThat(connectorsByService.values().iterator().next().length)
.isEqualTo(connectors.length + 1);
}
@Test

Loading…
Cancel
Save