dragon-zhang commented on code in PR #3776:
URL: https://github.com/apache/shenyu/pull/3776#discussion_r933963009
##########
shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java:
##########
@@ -49,27 +50,29 @@ public WebClientPlugin(final WebClient webClient) {
}
@Override
- protected Mono<ClientResponse> doRequest(final ServerWebExchange exchange,
final String httpMethod, final URI uri,
+ protected Mono<ResponseEntity<Void>> doRequest(final ServerWebExchange
exchange, final String httpMethod, final URI uri,
final HttpHeaders httpHeaders,
final Flux<DataBuffer> body) {
- // springWebflux5.3 mark #exchange() deprecated. because #echange
maybe make memory leak.
- // https://github.com/spring-projects/spring-framework/issues/25751
- // exchange is deprecated, so change to {@link
WebClient.RequestHeadersSpec#exchangeToMono(Function)}
- // exchangeToMono has two important bug:
- // 1.exchangeToMono can cause NPE when response body is null
- // 2.download file with exchangeToMono can't open
+ // Upgraded to Spring WebClient Retrieve utilizing RequestSpec &
ResponseSpec standard.
+ // OnStatus - is2xxSuccessful captures success responses
+ // OnStatus - isError captures all 4xx/5xx responses
+ // toBodilessEntity - captures 204 responses.
return webClient.method(HttpMethod.valueOf(httpMethod)).uri(uri)
.headers(headers -> headers.addAll(httpHeaders))
.body(BodyInserters.fromDataBuffers(body))
- .exchange()
- .doOnSuccess(res -> {
- if (res.statusCode().is2xxSuccessful()) {
-
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE,
ResultEnum.SUCCESS.getName());
- } else {
-
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE,
ResultEnum.ERROR.getName());
- }
+ .retrieve()
Review Comment:
You can continue to complete it according to your idea, but before the PR
get merged, I will do a simple pressure test on your PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]