I need to write a method which does
- Gets a
Location
header form an endpoint - Generates a series of
Some
which each should retrieved from theLocation
fetched from the first endpoint. - Need to return a
Flux<Some>
Which looks like this.
private WebClient client;
Flux<Some> getSome() {
// Get the Location header from an endpoint
client
.post()
.exchange()
.map(r -> r.headers().header("Location"))
// Now I need to keep invoking the Location endpoint for Some.class
// And Some.class has an attribute for pending/completion status.
// e.g.
while (true)
final Some some = client
.get()
.url(...) // the Location header value above
.retrieve()
.bodyToMono(Some.class)
.block()
;
}
}
How can I map the Mono<String>
to a Flux<Some>
while using the Some#status
attribute for completion?
// should return Flux<Some>
client
.post()
.exchange()
.map(r -> r.headers().header("Location"))
.flatMapMany(location -> {
// invokes location while retrieved Some#status is not `completed`
// @@?
})
;
inside the
flatMapMany
, perform the call that retrieves theLocation
. apply arepeat().takeUntil(loc -> loc.complete())
to it (still inside theflatMapMany
lambda)