Reputation: 21978
I need to write a method which does
Location
header form an endpointSome
which each should retrieved from the Location
fetched from the first endpoint.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`
// @@?
})
;
Upvotes: 0
Views: 282
Reputation: 28301
inside the flatMapMany
, perform the call that retrieves the Location
. apply a repeat().takeUntil(loc -> loc.complete())
to it (still inside the flatMapMany
lambda)
Upvotes: 3