Relative Content

Tag Archive for spring-webflux

Reactive Spring MessageSource

I am working on a WebFlux application with Reactor. I have an implementation of Spring MessageSource that in order to get an internationalized message, I call to a database where the messages are stored. The problem is I need one http header from the incoming http request in order to get this message from the database because is a parameter I need to get this message. That header is set in the Context of Reactor in a WebFilter but the problem is I cannot access that Reactor Context in the implementation of the MessageSource with Mono.deferContextual. How to do this?

How to return a custom response in case of error in webflux filter

this.handleException(exchange, throwable); });“` in the above code i would like to return a custom response eg as below { “its failed” }“` I tried it by returning it in the handleException method byte[] responseByte = JsonUtils.getObjectMapper() .writeValueAsString(“its failed”) .getBytes(StandardCharsets.UTF_8); exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); DataBuffer buffer = exchange.getResponse().bufferFactory().wrap(responseByte); return exchange.getResponse().writeWith(Flux.just(buffer)); But its not working and throwing the default exception […]

why ServerWebExchange-bodyToMono can not be subscribed

@RequestMapping(“/helloworld1234”) public Mono<String> helloWord122(ServerWebExchange exchange) { ServerRequest serverRequest = ServerRequest.create(exchange, HandlerStrategies.withDefaults().messageReaders()); // 1 serverRequest.bodyToMono(String.class).subscribe(body -> { log.info(“—” + body); }); // 2 Mono.just(“aaaa”).subscribe(aaa -> { log.info(“—” + aaa); }); return Mono.just(“newBody”); } why does the log.info(“—” + body); not print? i dont know why was that, its so complicated. spring-webflux