-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Expose toEntityFlux methods in WebClient.ResponseSpec #26023
Comments
Closing in favor of (if I'm not mistaken) your question on StackOverflow. |
Sorry, I didn't see Rossen's comment. Reopening. |
Yes the new The above should be straight forward with Now that |
@rstoyanchev Thank you for the quick response! 👍 If I may, a question regarding the implementation of .toEntityFlux() (I noticed because I wanted to submit the corresponding Kotlin extension functions) |
@mplain I see no need for an additional method in |
@rstoyanchev |
@robotmrv My guess is that when users would use |
Indeed as @mplain said it's about providing more structure and avoiding accidental mistakes. The |
@rstoyanchev, actually, looking at this code, where are the exceptions taken care of?
Comparing to another method:
Exceptions are handled in the |
This deprecation of As far as I can tell I can't do this with For more info, see: #24951 |
Can you clarify why? |
A simple attempt at refactoring is yielding an empty response body. I haven't figured out why and it's quite likely that I'm doing it wrong. I'm trying to take the following: .exchange()
.flatMap(response -> {
if (statusCode.isError()) {
return response.createException().flatMap(Mono::error);
} else {
var headers = response.headers().asHttpHeaders();
var pointer = JsonPointer.compile("/response/entities");
var body = response.body(streamingJsonBodyExtractor.toFlux(Entity.class, pointer));
return Mono.just(new ResponseWrapper(headers, body));
}
}); and I've attempted to refactor it into the following: .exchangeToMono(response -> {
if (statusCode.isError()) {
return response.createException().flatMap(Mono::error);
} else {
var headers = response.headers().asHttpHeaders();
var pointer = JsonPointer.compile("/response/entities");
var body = response.body(streamingJsonBodyExtractor.toFlux(Entity.class, pointer));
return Mono.just(new EntitiesResponse(headers, body));
}
}); If I instead use |
This is what the That said what actually consumes the body downstream? I ask is wrapping like that and letting it be consumed later opens a possibility that it may not be consumed at all, for example in case of a cancellation signal. |
As far as I can tell I can't use those methods as they expect that the response being decoded is in a very specific format. In my case the response is
The controller returns a |
This is probably fodder for another issue but could I propose some combination of the following method(s) on <T> Mono<ResponseEntity<T>> toEntity(BodyExtractor<T> extractor);
<T> Mono<ResponseEntity<T>> toEntity(Function<ClientResponse, Mono<T>> function);
<T> Mono<ResponseEntity<T>> toEntityFlux(Function<ClientResponse, Flux<T>> function); |
Hello!
I have a simple application that acts as a proxy between a client and a server
It receives a client request and passes it over to the server, then passes the server response back to the client
There is no need to process the request/response body, or buffer them in memory
Here is my current code:
After upgrading to WebFlux 5.3.0 I had to replace the
.exchange()
method with.exchangeToMono()
. This new method in turn calls.releaseIfNotConsumed()
, and apparently passing the body as aFlux<DataBuffer>
is not consuming it, so my client always gets a response with an empty body.What is the proper way to address my use case?
P.S. I created an issue here due to this request
The text was updated successfully, but these errors were encountered: