Browse Source

Merge branch '6.2.x'

# Conflicts:
#	spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java
pull/34993/merge
Juergen Hoeller 1 month ago
parent
commit
15a3f425cb
  1. 47
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java
  2. 47
      spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunction.java

47
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java

@ -43,6 +43,9 @@ public interface RouterFunction<T extends ServerResponse> { @@ -43,6 +43,9 @@ public interface RouterFunction<T extends ServerResponse> {
*/
Mono<HandlerFunction<T>> 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<T extends ServerResponse> { @@ -99,28 +102,6 @@ public interface RouterFunction<T extends ServerResponse> {
return and(RouterFunctions.nest(predicate, routerFunction));
}
/**
* Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given
* {@linkplain HandlerFilterFunction filter function}.
* @param <S> the filter return type
* @param filterFunction the filter to apply
* @return the filtered routing function
*/
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> 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<T extends ServerResponse> { @@ -155,5 +136,27 @@ public interface RouterFunction<T extends ServerResponse> {
return new RouterFunctions.AttributesRouterFunction<>(this, attributes);
}
/**
* Filter all {@linkplain HandlerFunction handler functions} routed by this function
* with the given {@linkplain HandlerFilterFunction filter function}.
* @param <S> the filter return type
* @param filterFunction the filter to apply
* @return the filtered routing function
*/
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) {
return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction);
}
/**
* Accept the given visitor.
* <p>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);
}
}

47
spring-webmvc/src/main/java/org/springframework/web/servlet/function/RouterFunction.java

@ -42,6 +42,9 @@ public interface RouterFunction<T extends ServerResponse> { @@ -42,6 +42,9 @@ public interface RouterFunction<T extends ServerResponse> {
*/
Optional<HandlerFunction<T>> 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<T extends ServerResponse> { @@ -98,28 +101,6 @@ public interface RouterFunction<T extends ServerResponse> {
return and(RouterFunctions.nest(predicate, routerFunction));
}
/**
* Filter all {@linkplain HandlerFunction handler functions} routed by this function with the given
* {@linkplain HandlerFilterFunction filter function}.
* @param <S> the filter return type
* @param filterFunction the filter to apply
* @return the filtered routing function
*/
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> 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<T extends ServerResponse> { @@ -154,5 +135,27 @@ public interface RouterFunction<T extends ServerResponse> {
return new RouterFunctions.AttributesRouterFunction<>(this, attributes);
}
/**
* Filter all {@linkplain HandlerFunction handler functions} routed by this function
* with the given {@linkplain HandlerFilterFunction filter function}.
* @param <S> the filter return type
* @param filterFunction the filter to apply
* @return the filtered routing function
*/
default <S extends ServerResponse> RouterFunction<S> filter(HandlerFilterFunction<T, S> filterFunction) {
return new RouterFunctions.FilteredRouterFunction<>(this, filterFunction);
}
/**
* Accept the given visitor.
* <p>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);
}
}

Loading…
Cancel
Save