From 23360d11a26e833f47bf5db52892e8ecd9ce8b1a Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 13 Apr 2017 12:39:16 +0200 Subject: [PATCH] Change codec auto-configuration in HandlerStrategies Since SPR-15415 and SPR-15435, the HandlerStrategies and its companion builder are now using the new CodecConfigurer infrastructure to configure codecs in a cross-cutting way. This commit looks for a custom instance of `HandlerStrategies.Builder` provided by the user, or create a default one if none was found. Fixes gh-8897 --- .../HttpHandlerAutoConfiguration.java | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java index 3a2b274449..febef45b23 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java @@ -31,8 +31,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.http.codec.HttpMessageReader; -import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.web.reactive.DispatcherHandler; import org.springframework.web.reactive.function.server.HandlerStrategies; @@ -72,8 +70,7 @@ public class HttpHandlerAutoConfiguration { @Bean public HttpHandler httpHandler() { - return WebHttpHandlerBuilder.applicationContext(this.applicationContext) - .build(); + return WebHttpHandlerBuilder.applicationContext(this.applicationContext).build(); } } @@ -86,47 +83,38 @@ public class HttpHandlerAutoConfiguration { private final WebSessionManager webSessionManager; - private final List> messageReaders; - - private final List> messageWriters; + private HandlerStrategies.Builder handlerStrategiesBuilder; private final List viewResolvers; public FunctionalConfig(ObjectProvider> webFilters, - ObjectProvider webSessionManager, - ObjectProvider>> messageReaders, - ObjectProvider>> messageWriters, - ObjectProvider> viewResolvers) { + ObjectProvider webSessionManager, + ObjectProvider handlerStrategiesBuilder, + ObjectProvider> viewResolvers) { this.webFilters = webFilters.getIfAvailable(); if (this.webFilters != null) { AnnotationAwareOrderComparator.sort(this.webFilters); } this.webSessionManager = webSessionManager.getIfAvailable(); - this.messageReaders = messageReaders.getIfAvailable(); - this.messageWriters = messageWriters.getIfAvailable(); + this.handlerStrategiesBuilder = handlerStrategiesBuilder.getIfAvailable(); this.viewResolvers = viewResolvers.getIfAvailable(); } @Bean - public HttpHandler httpHandler( - List> routerFunctions) { + public HttpHandler httpHandler(List> routerFunctions) { routerFunctions.sort(new AnnotationAwareOrderComparator()); RouterFunction routerFunction = routerFunctions.stream() - .reduce(RouterFunction::and).get(); - HandlerStrategies.Builder strategiesBuilder = HandlerStrategies.builder(); - if (this.messageReaders != null) { - this.messageReaders.forEach(strategiesBuilder::customMessageReader); - } - if (this.messageWriters != null) { - this.messageWriters.forEach(strategiesBuilder::customMessageWriter); + .reduce(RouterFunction::and).get(); + if (this.handlerStrategiesBuilder == null) { + this.handlerStrategiesBuilder = HandlerStrategies.builder(); } if (this.viewResolvers != null) { - this.viewResolvers.forEach(strategiesBuilder::viewResolver); + this.viewResolvers.forEach(this.handlerStrategiesBuilder::viewResolver); } WebHandler webHandler = RouterFunctions.toHttpHandler(routerFunction, - strategiesBuilder.build()); + this.handlerStrategiesBuilder.build()); WebHttpHandlerBuilder builder = WebHttpHandlerBuilder.webHandler(webHandler) - .sessionManager(this.webSessionManager); + .sessionManager(this.webSessionManager); builder.filters(this.webFilters); return builder.build(); }