WebFilterChain delegation nested in Mono.defer()

Issue: SPR-15520
This commit is contained in:
Rossen Stoyanchev 2017-05-08 15:36:31 -04:00
parent 47d6e4a332
commit 459457e1aa
2 changed files with 12 additions and 10 deletions

View File

@ -68,14 +68,16 @@ public class DefaultWebFilterChain implements WebFilterChain {
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange) { public Mono<Void> filter(ServerWebExchange exchange) {
if (this.index < this.filters.size()) { return Mono.defer(() -> {
WebFilter filter = this.filters.get(this.index); if (this.index < this.filters.size()) {
WebFilterChain chain = new DefaultWebFilterChain(this, this.index + 1); WebFilter filter = this.filters.get(this.index);
return filter.filter(exchange, chain); WebFilterChain chain = new DefaultWebFilterChain(this, this.index + 1);
} return filter.filter(exchange, chain);
else { }
return this.handler.handle(exchange); else {
} return this.handler.handle(exchange);
}
});
} }
} }

View File

@ -104,7 +104,7 @@ public class FilteringWebHandlerTests {
new FilteringWebHandler(targetHandler, Collections.singletonList(filter)) new FilteringWebHandler(targetHandler, Collections.singletonList(filter))
.handle(MockServerHttpRequest.get("/").toExchange()) .handle(MockServerHttpRequest.get("/").toExchange())
.block(Duration.ZERO); .block(Duration.ofSeconds(5));
assertTrue(filter.invoked()); assertTrue(filter.invoked());
assertTrue(targetHandler.invoked()); assertTrue(targetHandler.invoked());
@ -170,7 +170,7 @@ public class FilteringWebHandlerTests {
} }
private Mono<String> doAsyncWork() { private Mono<String> doAsyncWork() {
return Mono.just("123"); return Mono.delay(Duration.ofMillis(100L)).map(l -> "123");
} }
} }