Skip to content
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

WebFluxRequestExecutingMessageHandler directly creates WebClientResponseException rather than using provided create(...) factory method #3610

Closed
djgraff209 opened this issue Aug 6, 2021 · 0 comments · Fixed by #3611

Comments

@djgraff209
Copy link
Contributor

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

https://github.com/djgraff209/so68637283

@djgraff209 djgraff209 added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Aug 6, 2021
djgraff209 added a commit to djgraff209/spring-integration that referenced this issue Aug 6, 2021
This fix changes the WebFluxRequestExecutingMessageHandler
The change specifically changes the contruction of the
WebClientResponseException to use the `create` factory method.

This change addresses issue spring-projects#3610.
@artembilan artembilan added this to the 5.5.3 milestone Aug 9, 2021
@artembilan artembilan added backport 5.3.x in: webflux and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Aug 9, 2021
artembilan pushed a commit that referenced this issue Aug 9, 2021
Fixes #3610

This fix changes the WebFluxRequestExecutingMessageHandler
The change specifically changes the contruction of the
WebClientResponseException to use the `create` factory method.

* Added changes and unit test to cover updated code

Updated code to use simplified exception construction that is more tolerant
  of larger payloads.
Updated unit tests to check for specific exception types.

* Corrected checkstyle errors

Corrected checkstyle error in imports.
Corrected whitespace between casts.
Corrected trailing whitespace.

* Added @author


**Cherry-pick to `5.4.x` & `5.3.x`**
artembilan pushed a commit that referenced this issue Aug 9, 2021
Fixes #3610

This fix changes the WebFluxRequestExecutingMessageHandler
The change specifically changes the contruction of the
WebClientResponseException to use the `create` factory method.

* Added changes and unit test to cover updated code

Updated code to use simplified exception construction that is more tolerant
  of larger payloads.
Updated unit tests to check for specific exception types.

* Corrected checkstyle errors

Corrected checkstyle error in imports.
Corrected whitespace between casts.
Corrected trailing whitespace.

* Added @author


**Cherry-pick to `5.4.x` & `5.3.x`**
artembilan pushed a commit that referenced this issue Aug 9, 2021
Fixes #3610

This fix changes the WebFluxRequestExecutingMessageHandler
The change specifically changes the contruction of the
WebClientResponseException to use the `create` factory method.

* Added changes and unit test to cover updated code

Updated code to use simplified exception construction that is more tolerant
  of larger payloads.
Updated unit tests to check for specific exception types.

* Corrected checkstyle errors

Corrected checkstyle error in imports.
Corrected whitespace between casts.
Corrected trailing whitespace.

* Added @author

**Cherry-pick to `5.4.x` & `5.3.x`**
# Conflicts:
#	spring-integration-webflux/src/main/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandler.java
#	spring-integration-webflux/src/test/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandlerTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants