Spring WebClient出现问题,错误就像服务器重置conn一样。但是当我用RestTemplate替换时,问题消失了。有什么帮助吗?
2020-10-08T23:30:36.515+07:00|2|ERROR|global-spi-engine|2417bb1abef50e40,2417bb1abef50e40,true,|73700|reactor-http-nio-8|o.s.w.s.adapter.HttpWebHandlerAdapter|[5e52ab55] 500 Server Error for HTTP POST "/requests"
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.8.0_241]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ Request to GET https://*** [DefaultWebClient]
|_ checkpoint ⇢ Handler com.ascendcorp.orbit.globalspiengine.service.api.controller.SpiController#call(Map, AbstractSPIRequestDTO) [DispatcherHandler]
|_ checkpoint ⇢ org.springframework.cloud.sleuth.instrument.web.TraceWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "/requests" [ExceptionHandlingWebHandler]
HttpHeaders headers2 = new HttpHeaders();
headers2.setAll(request.getHeaders());
HttpEntity entity = new HttpEntity(headers2);
ResponseEntity<String> response = restTemplate.exchange(request.getUrl(), HttpMethod.GET, entity, String.class);
return Mono.justOrEmpty(response);
// WebClient.RequestBodySpec requestBodySpec = WebClient.builder()
// .filters(exchangeFilterFunctions -> {
// exchangeFilterFunctions.add(logRequest());
// exchangeFilterFunctions.add(logResponse());
// }).build()
// .method(request.getMethod())
// .uri(request.getUrl())
// .contentType(MediaType.parseMediaType("application/json"))
// .contentLength(0)
// .header("Authorization", request.getHeaders().get("Authorization"))
// .header("Accept", "*/*");
//// requestBodySpec.body(BodyInserters.fromValue(request.getBodyContent()));
//
// return requestBodySpec.exchange()
// .flatMap(clientResponse -> {
// try {
// return clientResponse.toEntity(Class.forName("java.lang.String"));
// } catch (Exception e) {
// throw new ServerWebInputException("Class not found: " + e);
// }
// });