Polish "Simplify the configuration of the ProtocolHandler"

Closes gh-16342
pull/16474/head
Madhura Bhave 6 years ago
parent 2eaa64f82e
commit ad767ca4e1

@ -78,7 +78,7 @@ abstract class ReactiveWebServerFactoryConfiguration {
public TomcatReactiveWebServerFactory tomcatReactiveWebServerFactory(
ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,
ObjectProvider<TomcatContextCustomizer> contextCustomizers,
ObjectProvider<TomcatProtocolHandlerCustomizer> protocolHandlerCustomizers) {
ObjectProvider<TomcatProtocolHandlerCustomizer<?>> protocolHandlerCustomizers) {
TomcatReactiveWebServerFactory factory = new TomcatReactiveWebServerFactory();
factory.getTomcatConnectorCustomizers().addAll(
connectorCustomizers.orderedStream().collect(Collectors.toList()));

@ -68,7 +68,7 @@ class ServletWebServerFactoryConfiguration {
public TomcatServletWebServerFactory tomcatServletWebServerFactory(
ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,
ObjectProvider<TomcatContextCustomizer> contextCustomizers,
ObjectProvider<TomcatProtocolHandlerCustomizer> protocolHandlerCustomizers) {
ObjectProvider<TomcatProtocolHandlerCustomizer<?>> protocolHandlerCustomizers) {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.getTomcatConnectorCustomizers().addAll(
connectorCustomizers.orderedStream().collect(Collectors.toList()));

@ -74,7 +74,7 @@ public interface ConfigurableTomcatWebServerFactory extends ConfigurableWebServe
* @param tomcatProtocolHandlerCustomizers the customizers to add
*/
void addProtocolHandlerCustomizers(
TomcatProtocolHandlerCustomizer... tomcatProtocolHandlerCustomizers);
TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers);
/**
* Set the character encoding to use for URL decoding. If not specified 'UTF-8' will

@ -34,9 +34,11 @@ import org.apache.catalina.core.AprLifecycleListener;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http2.Http2Protocol;
import org.apache.tomcat.util.scan.StandardJarScanFilter;
import org.springframework.boot.util.LambdaSafe;
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory;
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
import org.springframework.boot.web.server.WebServer;
@ -72,7 +74,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
private List<TomcatConnectorCustomizer> tomcatConnectorCustomizers = new ArrayList<>();
private List<TomcatProtocolHandlerCustomizer> tomcatProtocolHandlerCustomizers = new ArrayList<>();
private List<TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizers = new ArrayList<>();
private String protocol = DEFAULT_PROTOCOL;
@ -170,10 +172,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler());
}
this.tomcatProtocolHandlerCustomizers.forEach(
(customizer) -> customizer.customize(connector.getProtocolHandler()));
invokeProtocolHandlerCustomizers(connector);
if (getUriEncoding() != null) {
connector.setURIEncoding(getUriEncoding().name());
}
@ -190,6 +189,15 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
}
}
@SuppressWarnings("unchecked")
private void invokeProtocolHandlerCustomizers(Connector connector) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
LambdaSafe
.callbacks(TomcatProtocolHandlerCustomizer.class,
this.tomcatProtocolHandlerCustomizers, protocolHandler)
.invoke((customizer) -> customizer.customize(protocolHandler));
}
private void customizeProtocol(AbstractProtocol<?> protocol) {
if (getAddress() != null) {
protocol.setAddress(getAddress());
@ -287,7 +295,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
* @param tomcatProtocolHandlerCustomizers the customizers to set
*/
public void setTomcatProtocolHandlerCustomizers(
Collection<? extends TomcatProtocolHandlerCustomizer> tomcatProtocolHandlerCustomizers) {
Collection<? extends TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizers) {
Assert.notNull(tomcatProtocolHandlerCustomizers,
"TomcatProtocolHandlerCustomizers must not be null");
this.tomcatProtocolHandlerCustomizers = new ArrayList<>(
@ -301,7 +309,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
*/
@Override
public void addProtocolHandlerCustomizers(
TomcatProtocolHandlerCustomizer... tomcatProtocolHandlerCustomizers) {
TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers) {
Assert.notNull(tomcatProtocolHandlerCustomizers,
"TomcatProtocolHandlerCustomizers must not be null");
this.tomcatProtocolHandlerCustomizers
@ -313,7 +321,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
* will be applied to the Tomcat {@link Connector}.
* @return the customizers that will be applied
*/
public Collection<TomcatProtocolHandlerCustomizer> getTomcatProtocolHandlerCustomizers() {
public Collection<TomcatProtocolHandlerCustomizer<?>> getTomcatProtocolHandlerCustomizers() {
return this.tomcatProtocolHandlerCustomizers;
}

@ -58,9 +58,11 @@ import org.apache.catalina.webresources.AbstractResourceSet;
import org.apache.catalina.webresources.EmptyResource;
import org.apache.catalina.webresources.StandardRoot;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http2.Http2Protocol;
import org.apache.tomcat.util.scan.StandardJarScanFilter;
import org.springframework.boot.util.LambdaSafe;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.MimeMappings;
import org.springframework.boot.web.server.WebServer;
@ -117,7 +119,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
private List<TomcatConnectorCustomizer> tomcatConnectorCustomizers = new ArrayList<>();
private List<TomcatProtocolHandlerCustomizer> tomcatProtocolHandlerCustomizers = new ArrayList<>();
private List<TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizers = new ArrayList<>();
private List<Connector> additionalTomcatConnectors = new ArrayList<>();
@ -305,10 +307,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
customizeProtocol((AbstractProtocol<?>) connector.getProtocolHandler());
}
this.tomcatProtocolHandlerCustomizers.forEach(
(customizer) -> customizer.customize(connector.getProtocolHandler()));
invokeProtocolHandlerCustomizers(connector);
if (getUriEncoding() != null) {
connector.setURIEncoding(getUriEncoding().name());
}
@ -331,6 +330,15 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
}
}
@SuppressWarnings("unchecked")
private void invokeProtocolHandlerCustomizers(Connector connector) {
ProtocolHandler protocolHandler = connector.getProtocolHandler();
LambdaSafe
.callbacks(TomcatProtocolHandlerCustomizer.class,
this.tomcatProtocolHandlerCustomizers, protocolHandler)
.invoke((customizer) -> customizer.customize(protocolHandler));
}
private void customizeSsl(Connector connector) {
new SslConnectorCustomizer(getSsl(), getSslStoreProvider()).customize(connector);
if (getHttp2() != null && getHttp2().isEnabled()) {
@ -631,7 +639,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
* @param tomcatProtocolHandlerCustomizer the customizers to set
*/
public void setTomcatProtocolHandlerCustomizers(
Collection<? extends TomcatProtocolHandlerCustomizer> tomcatProtocolHandlerCustomizer) {
Collection<? extends TomcatProtocolHandlerCustomizer<?>> tomcatProtocolHandlerCustomizer) {
Assert.notNull(tomcatProtocolHandlerCustomizer,
"TomcatProtocolHandlerCustomizers must not be null");
this.tomcatProtocolHandlerCustomizers = new ArrayList<>(
@ -645,7 +653,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
*/
@Override
public void addProtocolHandlerCustomizers(
TomcatProtocolHandlerCustomizer... tomcatProtocolHandlerCustomizers) {
TomcatProtocolHandlerCustomizer<?>... tomcatProtocolHandlerCustomizers) {
Assert.notNull(tomcatProtocolHandlerCustomizers,
"TomcatProtocolHandlerCustomizers must not be null");
this.tomcatProtocolHandlerCustomizers
@ -657,7 +665,7 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
* will be applied to the Tomcat {@link Connector}.
* @return the customizers that will be applied
*/
public Collection<TomcatProtocolHandlerCustomizer> getTomcatProtocolHandlerCustomizers() {
public Collection<TomcatProtocolHandlerCustomizer<?>> getTomcatProtocolHandlerCustomizers() {
return this.tomcatProtocolHandlerCustomizers;
}

Loading…
Cancel
Save