I have the following code inside a webfilter in my Srping webflux app
return this.authenticationConverter.convert(exchange)
.onErrorResume(AuthenticationException.class, (ex) -> {
this.logger.debug("Failed to process OIDC Back-Channel Logout", ex);
return ex instanceof AuthenticationServiceException
? Mono.error(ex)
: this.handleAuthenticationFailure(exchange, ex).then(Mono.empty());
})
.switchIfEmpty(Mono.defer(() -> {
logger.debug("No authentication found, continuing filter chain.");
return chain.filter(exchange);
}).then(Mono.empty()))
.flatMap(authenticationManager::authenticate)
.onErrorResume(AuthenticationException.class, (ex) -> {
this.logger.info("Failed to process OIDC Back-Channel Logout", ex);
return ex instanceof AuthenticationServiceException
? Mono.error(ex)
: this.handleAuthenticationFailure(exchange, ex).then(Mono.empty());
})
.flatMap(authentication -> {
WebFilterExchange webFilterExchange = new WebFilterExchange(exchange, chain);
logger.debug("Authentication successful, proceeding with logout.");
return this.logoutHandler.logout(webFilterExchange, authentication);
});
Although the code is executed successfully and reaches the line .flatMap(authentication -> {
, the code inside the flatmap is never executed.
I feel that I have gotten something wrong about the reactive model, but don't know what.
I tried debugging (in Intellij IDEA), but the flatmap callback is always skipped. I am expecting the code inside the flatmap to be executed.
I have the following code inside a webfilter in my Srping webflux app
return this.authenticationConverter.convert(exchange)
.onErrorResume(AuthenticationException.class, (ex) -> {
this.logger.debug("Failed to process OIDC Back-Channel Logout", ex);
return ex instanceof AuthenticationServiceException
? Mono.error(ex)
: this.handleAuthenticationFailure(exchange, ex).then(Mono.empty());
})
.switchIfEmpty(Mono.defer(() -> {
logger.debug("No authentication found, continuing filter chain.");
return chain.filter(exchange);
}).then(Mono.empty()))
.flatMap(authenticationManager::authenticate)
.onErrorResume(AuthenticationException.class, (ex) -> {
this.logger.info("Failed to process OIDC Back-Channel Logout", ex);
return ex instanceof AuthenticationServiceException
? Mono.error(ex)
: this.handleAuthenticationFailure(exchange, ex).then(Mono.empty());
})
.flatMap(authentication -> {
WebFilterExchange webFilterExchange = new WebFilterExchange(exchange, chain);
logger.debug("Authentication successful, proceeding with logout.");
return this.logoutHandler.logout(webFilterExchange, authentication);
});
Although the code is executed successfully and reaches the line .flatMap(authentication -> {
, the code inside the flatmap is never executed.
I feel that I have gotten something wrong about the reactive model, but don't know what.
I tried debugging (in Intellij IDEA), but the flatmap callback is always skipped. I am expecting the code inside the flatmap to be executed.
Share Improve this question edited Feb 2 at 15:08 Δημήτρης Τοπαλίδης asked Feb 2 at 15:08 Δημήτρης ΤοπαλίδηςΔημήτρης Τοπαλίδης 11 bronze badge 01 Answer
Reset to default 1flatMap is an operator that transforms a value emitted asynchronously, usually "flatting" nested publishers.
In your case, the .then(Mono.empty()))
call turns the emitted value into "empty". Since no value is emitted after that, the flatMap operator is never called. Maybe the order of operators isn't right here?