|
@@ -12,6 +12,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.web.reactive.function.BodyInserters;
|
|
import org.springframework.web.reactive.function.BodyInserters;
|
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
|
|
+import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
@@ -32,6 +33,8 @@ public class HttpClientUtils {
|
|
|
|
|
|
private static final Integer DEFAULT_REQUEST_TIMEOUT = 10000;
|
|
private static final Integer DEFAULT_REQUEST_TIMEOUT = 10000;
|
|
|
|
|
|
|
|
+ private static final Integer MAX_IN_MEMORY_SIZE = 10 * 1024 * 1024;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* get请求解析成字符串
|
|
* get请求解析成字符串
|
|
*
|
|
*
|
|
@@ -206,7 +209,6 @@ public class HttpClientUtils {
|
|
Mono<String> resp = createWebClientWithConnectAndReadTimeOuts().post().uri(url)
|
|
Mono<String> resp = createWebClientWithConnectAndReadTimeOuts().post().uri(url)
|
|
.contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(jsonBody), Object.class).retrieve()
|
|
.contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(jsonBody), Object.class).retrieve()
|
|
.bodyToMono(String.class).timeout(Duration.ofMillis(DEFAULT_REQUEST_TIMEOUT));
|
|
.bodyToMono(String.class).timeout(Duration.ofMillis(DEFAULT_REQUEST_TIMEOUT));
|
|
-
|
|
|
|
return resp.block();
|
|
return resp.block();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -253,7 +255,12 @@ public class HttpClientUtils {
|
|
// create a client http connector using above http client
|
|
// create a client http connector using above http client
|
|
ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
|
|
ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
|
|
// use this configured http connector to build the web client
|
|
// use this configured http connector to build the web client
|
|
- return WebClient.builder().clientConnector(connector).build();
|
|
|
|
|
|
+ return WebClient.builder()
|
|
|
|
+ .exchangeStrategies(ExchangeStrategies.builder()
|
|
|
|
+ .codecs(
|
|
|
|
+ clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs().maxInMemorySize(MAX_IN_MEMORY_SIZE))
|
|
|
|
+ .build())
|
|
|
|
+ .clientConnector(connector).build();
|
|
}
|
|
}
|
|
|
|
|
|
private static MultiValueMap<String, String> getRequestParamMap(Map<String, String> params) {
|
|
private static MultiValueMap<String, String> getRequestParamMap(Map<String, String> params) {
|