From 30bd3d873682734502554a25db398906215c81f1 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 6 Dec 2016 17:12:35 +0100 Subject: [PATCH] Allow use of WebFilters in RouterFunction This commit changes RouterFunctions.toHttpHandler to return HttpWebHandlerAdapter (instead of HttpHandler), so that WebFilters and WebExceptionHandler can be applied to it. Issue: SPR-14979 --- .../web/reactive/function/RouterFunctions.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunctions.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunctions.java index f699314d6f..bff092c87a 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunctions.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/function/RouterFunctions.java @@ -27,7 +27,9 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.util.Assert; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebHandler; import org.springframework.web.server.adapter.HttpWebHandlerAdapter; +import org.springframework.web.server.adapter.WebHttpHandlerBuilder; /** * Central entry point to Spring's functional web framework. @@ -140,7 +142,7 @@ public abstract class RouterFunctions { /** * Convert the given {@linkplain RouterFunction router function} into a {@link HttpHandler}. * This conversion uses {@linkplain HandlerStrategies#builder() default strategies}. - *

The returned {@code HttpHandler} can be adapted to run in + *

The returned handler can be adapted to run in *

+ *

Note that {@code HttpWebHandlerAdapter} also implements {@link WebHandler}, allowing + * for additional filter and exception handler registration through + * {@link WebHttpHandlerBuilder}. * @param routerFunction the router function to convert * @return an http handler that handles HTTP request using the given router function */ - public static HttpHandler toHttpHandler(RouterFunction routerFunction) { + public static HttpWebHandlerAdapter toHttpHandler(RouterFunction routerFunction) { return toHttpHandler(routerFunction, HandlerStrategies.withDefaults()); } @@ -172,11 +177,13 @@ public abstract class RouterFunctions { *

  • Undertow using the * {@link org.springframework.http.server.reactive.UndertowHttpHandlerAdapter}.
  • * + *

    Note that {@code HttpWebHandlerAdapter} also implements {@link WebHandler}, allowing + * for additional filter and exception handler registration through * @param routerFunction the router function to convert * @param strategies the strategies to use * @return an http handler that handles HTTP request using the given router function */ - public static HttpHandler toHttpHandler(RouterFunction routerFunction, HandlerStrategies strategies) { + public static HttpWebHandlerAdapter toHttpHandler(RouterFunction routerFunction, HandlerStrategies strategies) { Assert.notNull(routerFunction, "RouterFunction must not be null"); Assert.notNull(strategies, "HandlerStrategies must not be null");