fix(测试跟踪): 测试计划报告导出报错

--bug=1037585 --user=陈建星 【测试跟踪】github#29596,测试计划报告导出报错 https://www.tapd.cn/55049933/s/1521192
This commit is contained in:
AgAngle 2024-05-27 11:48:58 +08:00 committed by Craftsman
parent ab132746fa
commit 45100cee3d
2 changed files with 24 additions and 7 deletions

View File

@ -18,7 +18,7 @@ import java.util.List;
public class JsonUtils { public class JsonUtils {
private static final ObjectMapper objectMapper = new ObjectMapper(); 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 { static {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

View File

@ -25,11 +25,14 @@ import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.protocol.HttpContext; import org.apache.hc.core5.http.protocol.HttpContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; 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 org.springframework.web.client.RestTemplate;
import java.io.IOException; import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.SocketException; import java.net.SocketException;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -43,13 +46,13 @@ public class RestTemplateConfig {
private final static int SOCKET_TIMEOUT = 200 * 1000; private final static int SOCKET_TIMEOUT = 200 * 1000;
@Bean @Bean
public RestTemplate restTemplate() { public RestTemplate restTemplate(ObjectMapper objectMapper, HttpClient httpClient) {
return setTemplate(); return setTemplate(objectMapper, httpClient);
} }
@Bean @Bean
public RestTemplate restTemplateWithTimeOut() { public RestTemplate restTemplateWithTimeOut(ObjectMapper objectMapper, HttpClient httpClient) {
return setTemplate(); return setTemplate(objectMapper, httpClient);
} }
@Bean @Bean
@ -89,9 +92,23 @@ public class RestTemplateConfig {
return mapper; return mapper;
} }
private RestTemplate setTemplate() { public RestTemplate setTemplate(ObjectMapper objectMapper, HttpClient httpClient) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient())); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
List<HttpMessageConverter<?>> 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; return restTemplate;
} }