Skip to content

Add toEntityFlux with BodyExtractor to WebClient.ResponseSpec #26099

@HaloFour

Description

@HaloFour

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 case retrieve().entityToFlux(DataBuffer.class) looks like it comes close to satisfying this use case, but I don't see a way with ResponseSpec 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.:

{
    "response": {
        "entities": [ ]
    }
}

We're currently using exchange with a custom BodyExtractor<Flux<T>> which can scan into the JSON response to the array and stream the individual elements which we return in a ResponseEntity<Flux<T>> so that we can also return the response headers and status code. We then flow this Flux<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.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by anothertype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions