diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java index e61fbd97e7..d49903fc14 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/utils/JsonUtils.java @@ -18,7 +18,7 @@ import java.util.List; public class JsonUtils { private static final ObjectMapper objectMapper = new ObjectMapper(); - public static final int DEFAULT_MAX_STRING_LEN = 20_000_000_0; + public static final int DEFAULT_MAX_STRING_LEN = Integer.MAX_VALUE; static { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java index 43b782e73e..d46e84920c 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/autoconfigure/RestTemplateConfig.java @@ -25,11 +25,14 @@ import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.http.protocol.HttpContext; import org.springframework.context.annotation.Bean; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; import java.io.IOException; import java.net.ConnectException; import java.net.SocketException; +import java.util.List; import java.util.concurrent.TimeUnit; @@ -43,13 +46,13 @@ public class RestTemplateConfig { private final static int SOCKET_TIMEOUT = 200 * 1000; @Bean - public RestTemplate restTemplate() { - return setTemplate(); + public RestTemplate restTemplate(ObjectMapper objectMapper, HttpClient httpClient) { + return setTemplate(objectMapper, httpClient); } @Bean - public RestTemplate restTemplateWithTimeOut() { - return setTemplate(); + public RestTemplate restTemplateWithTimeOut(ObjectMapper objectMapper, HttpClient httpClient) { + return setTemplate(objectMapper, httpClient); } @Bean @@ -89,9 +92,23 @@ public class RestTemplateConfig { return mapper; } - private RestTemplate setTemplate() { + public RestTemplate setTemplate(ObjectMapper objectMapper, HttpClient httpClient) { RestTemplate restTemplate = new RestTemplate(); - restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient())); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); + + List> messageConverters = restTemplate.getMessageConverters(); + for (int i = 0; i < messageConverters.size(); i++) { + if (messageConverters.get(i) instanceof MappingJackson2HttpMessageConverter) { + // 使用自定义ObjectMapper创建HttpMessageConverter + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setObjectMapper(objectMapper); + messageConverters.set(i, converter); + } + } + + // 将HttpMessageConverter加入到RestTemplate中 + restTemplate.setMessageConverters(messageConverters); + return restTemplate; }