-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Milestone
Description
In what version(s) of Spring Integration are you seeing this issue?
5.3.8.RELEASE
Describe the bug
The WebFluxRequestExecutingMessageHandler
is directly creating a WebClientResponseException
rather than using the provided create
factory methods. This can cause some confusion when attempting to use the customizeMonoReply
method to trap and provide a default response payload.
To Reproduce
Assume a RESTful endpoint that will return an HTTP/404 error when an entity is not found.
Using an integration flow similar to the following:
@Bean
public IntegrationFlow getMixEntryFlowReactive() {
final WebClient webClient =
webClientBuilder.defaultHeaders(
headers -> headers.setBasicAuth("api", "s3cr3t")
)
.build();
final String defaultPayload = "{ \"id\": -1, \"name\": null }";
return f->
f.enrich(
e -> e.requestSubFlow(
sf -> sf.handle(
WebFlux.outboundGateway("http://localhost:8080/mix-entry/name/{mixEntryName}", webClient)
.httpMethod(HttpMethod.GET)
.uriVariable("mixEntryName", "payload")
.expectedResponseType(String.class)
,
ec -> ec.customizeMonoReply(
(Message<?> message, Mono<?> mono) ->
mono.onErrorResume(
WebClientResponseException.NotFound.class,
ex1 -> Mono.just(ex1)
.map(ex -> defaultPayload)
.switchIfEmpty((Mono)mono)
)
)
)
.logAndReply()
)
.headerExpression("mix-entry-id", "#jsonPath(payload, '$.id')")
)
.logAndReply();
}
Expected behavior
Expectation is that resulting message, when an HTTP/404 error occurs, contains the header mix-entry-id
with the value of -1
.
Sample