diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java index 7cad3055a35..bb696a14b34 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java @@ -43,6 +43,9 @@ public interface RouterFunction { */ Mono> route(ServerRequest request); + + // Default methods for composition and filtering + /** * Return a composed routing function that first invokes this function, * and then invokes the {@code other} function (of the same response type {@code T}) @@ -99,28 +102,6 @@ public interface RouterFunction { return and(RouterFunctions.nest(predicate, routerFunction)); } - /** - * Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given - * {@linkplain HandlerFilterFunction filter function}. - * @param the filter return type - * @param filterFunction the filter to apply - * @return the filtered routing function - */ - default RouterFunction filter(HandlerFilterFunction filterFunction) { - return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction); - } - - /** - * Accept the given visitor. Default implementation calls - * {@link RouterFunctions.Visitor#unknown(RouterFunction)}; composed {@code RouterFunction} - * implementations are expected to call {@code accept} for all components that make up this - * router function. - * @param visitor the visitor to accept - */ - default void accept(RouterFunctions.Visitor visitor) { - visitor.unknown(this); - } - /** * Return a new routing function with the given attribute. * @param name the attribute name @@ -155,5 +136,27 @@ public interface RouterFunction { return new RouterFunctions.AttributesRouterFunction<>(this, attributes); } + /** + * Filter all {@linkplain HandlerFunction handler functions} routed by this function + * with the given {@linkplain HandlerFilterFunction filter function}. + * @param the filter return type + * @param filterFunction the filter to apply + * @return the filtered routing function + */ + default RouterFunction filter(HandlerFilterFunction filterFunction) { + return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction); + } + + /** + * Accept the given visitor. + *

The default implementation calls + * {@link RouterFunctions.Visitor#unknown(RouterFunction)}; composed {@code RouterFunction} + * implementations are expected to call {@code accept} for all components that make up this + * router function. + * @param visitor the visitor to accept + */ + default void accept(RouterFunctions.Visitor visitor) { + visitor.unknown(this); + } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunction.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunction.java index aebcc285440..47bda0757fb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunction.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunction.java @@ -42,6 +42,9 @@ public interface RouterFunction { */ Optional> route(ServerRequest request); + + // Default methods for composition and filtering + /** * Return a composed routing function that first invokes this function, * and then invokes the {@code other} function (of the same response type {@code T}) @@ -98,28 +101,6 @@ public interface RouterFunction { return and(RouterFunctions.nest(predicate, routerFunction)); } - /** - * Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given - * {@linkplain HandlerFilterFunction filter function}. - * @param the filter return type - * @param filterFunction the filter to apply - * @return the filtered routing function - */ - default RouterFunction filter(HandlerFilterFunction filterFunction) { - return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction); - } - - /** - * Accept the given visitor. Default implementation calls - * {@link RouterFunctions.Visitor#unknown(RouterFunction)}; composed {@code RouterFunction} - * implementations are expected to call {@code accept} for all components that make up this - * router function. - * @param visitor the visitor to accept - */ - default void accept(RouterFunctions.Visitor visitor) { - visitor.unknown(this); - } - /** * Return a new routing function with the given attribute. * @param name the attribute name @@ -154,5 +135,27 @@ public interface RouterFunction { return new RouterFunctions.AttributesRouterFunction<>(this, attributes); } + /** + * Filter all {@linkplain HandlerFunction handler functions} routed by this function + * with the given {@linkplain HandlerFilterFunction filter function}. + * @param the filter return type + * @param filterFunction the filter to apply + * @return the filtered routing function + */ + default RouterFunction filter(HandlerFilterFunction filterFunction) { + return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction); + } + + /** + * Accept the given visitor. + *

The default implementation calls + * {@link RouterFunctions.Visitor#unknown(RouterFunction)}; composed {@code RouterFunction} + * implementations are expected to call {@code accept} for all components that make up this + * router function. + * @param visitor the visitor to accept + */ + default void accept(RouterFunctions.Visitor visitor) { + visitor.unknown(this); + } }