-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Add toEntityFlux with BodyExtractor to WebClient.ResponseSpec #26099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not 100% sure but I think my use cases might be solved with a few additional APIs to
|
Thanks for the extra details. For your first scenario, have you seen the Javadoc for onStatus where you can can return For extracting to Mono<ResponseEntity<T>> toEntity(BodyExtractor<T> extractor);
Mono<ResponseEntity<T>> toEntity(Function<ClientResponse, Mono<T>> function); For those you could use Mono<ResponseWrapper<Foo>> result = webClient.get().uri("/foo/1")
.exchangeToMono(response -> response.body(fooExtractor).map(foo -> new ResponseWrapper(...))); That leaves <T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(BodyExtractor<T, ClientHttpResponse> extractor); |
Thanks for that. I'll give it a try. I tried to follow the code path for that case but I must've misinterpreted it. Empty Mono's are weird beasts. |
The following approach does work, thank you for that: .retrieve()
.onRawStatus(status -> true, () -> Mono.empty())
.toEntityFlux(DataBuffer.class) I do think that |
You can create a static handler with an appropriate name and a note if you want to make it more obvious: /** Handler that suppresses default status error handling */
final static Function<ClientResponse, Mono<? extends Throwable>> NOOP_ERROR_HANDLER = () -> Mono.empty(); and then: .retrieve()
.onRawStatus(status -> true, NOOP_ERROR_HANDLER)
.toEntityFlux(DataBuffer.class) |
Thanks for your help, I was able to port over almost all of our uses of |
Sure, go ahead and submit. |
Uh oh!
There was an error while loading. Please reload this page.
Affects: Spring WebFlux 5.3.1
I started a conversation over on #26023 (comment) but it feels more appropriate to open a new issue.
If the plan is to remove the
WebClient#exchange
method entirely (as described here) how can we solve for those cases that aren't currently solved for using the alternative methods?I have two scenarios in my case base which seem to require
WebClient#exchange
:The first scenario is a series of endpoints which more or less act as a proxy to an upstream service. We use
Flux<DataBuffer>
to stream the raw data to/from the client. In this caseretrieve().entityToFlux(DataBuffer.class)
looks like it comes close to satisfying this use case, but I don't see a way withResponseSpec
to disable the default status code handling entirely, which is what I need.The second scenario are some endpoints where we make an upstream service request and get back a large JSON response containing an array nested in a root object, e.g.:
We're currently using
exchange
with a customBodyExtractor<Flux<T>>
which can scan into the JSON response to the array and stream the individual elements which we return in aResponseEntity<Flux<T>>
so that we can also return the response headers and status code. We then flow thisFlux<T>
back to the controller where it is mapped to transform each entity and stream it down to the client. See #24951 for more details.I've not fully evaluated where we're using
exchange
and whether or not they all fit into these two cases so I might be missing some scenarios.The text was updated successfully, but these errors were encountered: