Clarify behavior for WebClient statusHandlers
See original GitHub issueDuring Spring Boot 2.2 upgrade (from 2.1.x) we’ve noticed regression in tests using webclient.
Scenario: Call an enpoint returning 404 NOT_FOUND (with non-empty response body)
Expected: webclient returns empty Mono instance
spring-webflux >= 5.2.0 Actual: webclient call returns an non-empty response but the wrapped object has nothing more than nulls inside - unit test fails.
spring-webflux == 5.1.14 Actual: webclient call returns an empty response - unit test works fine.
Here is a sample that reproduces the problem: https://github.com/jmayday/emptymono Please have a look at this unit test (it uses Wiremock) - shouldReturnEmptyObjectFor404WithResponseBody
Unit test result:
java.lang.AssertionError:
Expecting an empty Optional but was containing value: <MyEntity(id=null, name=null, owner=null)>.
Pay attention, that if we’ll modify response body in wiremock mapping and replace body
{"error_code":404,"message":"Page not found"}
with empty body, then test will work.
Is this a spring-webflux 5.2.x regression or I’m misusing it?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
@jmayday see the updated to the Javadoc in the referenced commit above. I’ve clarified the various cases and provides suggestions for your case.
I think you’d have to use an
ExchangeFilterFunction
to accomplish this. TheonStatus
handlers are designed to map to an exception; not to an alternative (empty) result.As said in the commit message, returning an empty result prior to a9b3d95 (eg 5.1.14) will actually leak memory (i.e. the body), so it never “worked” correctly in the first place.