I want to create a conditional WebFilter that executes one logic if ServerWebExchangeMatcher matches, and another logic if it does not match.
The following already works for a "positive" match, by using .filter(..::isMatch). But how could I add a .orElse() method here into the flow?
class PathFilter implements org.springframework.web.server.WebFilter {
private ServerWebExchangeMatcher paths;
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
//TODO how to add a "no-match" execution?
return this.paths.matches(exchange)
.filter(ServerWebExchangeMatcher.MatchResult::isMatch)
.flatMap(...)
.then();
}
}