Inside a REST controller, I need to call a REST to obtain a value to be used as a URI variable to a second REST call.
@PostMapping
public void abbina(@RequestBody DocumentsUploadRequest documentsUploadRequest) {
Mono<GetResult> result = WebClient
.create(url)
.get()
.....
.retrieve()
.bodyToMono(GetResult.class)
;
WebClient.post()
.uri(...)
.path("/{partita}")
.build(result.block().getValue()))
.....
.bodyToMono(PostResult.class)
....
}
The problem is that inside a WebFlux REST isn't possibile call block on a mono/flux.
The code throw
java.lang.IllegalStateException block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http
I tried to change
.build(result.block().getValue()))
with
.build(result.share().block().getValue()))
But now the problem is that result.share().block()
hangs indefinitely.