fix(测试跟踪): 调用缺陷平台接口支持配置系统Http代理

--bug=1014343 --user=陈建星 【测试跟踪】github# 15226,与#7586同样的问题,在metersphere需要使用外网代理访问外网的环境里,在宿主机和docker里都设置了外网代理环境变量,且开通了对应外网访问权限,但在进行jira cloud集成的时候,仍然报连接超时错误 https://www.tapd.cn/55049933/s/1189919
This commit is contained in:
chenjianxing 2022-06-24 14:25:57 +08:00 committed by jianxing
parent 5f20dd00e8
commit c81fa9aed0
2 changed files with 2 additions and 31 deletions

View File

@ -26,24 +26,16 @@ import io.metersphere.track.service.IssuesService;
import io.metersphere.track.service.TestCaseIssueService;
import io.metersphere.track.service.TestCaseService;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Whitelist;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.net.URLDecoder;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
@ -52,8 +44,6 @@ import java.util.stream.Collectors;
public abstract class AbstractIssuePlatform implements IssuesPlatform {
private static RestTemplate restTemplate;
protected IntegrationService integrationService;
protected TestCaseIssueService testCaseIssueService;
protected TestCaseIssuesMapper testCaseIssuesMapper;
@ -62,7 +52,6 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
protected IssuesMapper issuesMapper;
protected ExtIssuesMapper extIssuesMapper;
protected ResourceService resourceService;
protected RestTemplate restTemplateIgnoreSSL;
protected UserService userService;
protected ProjectMapper projectMapper;
protected String testCaseId;
@ -79,25 +68,6 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
return key;
}
static {
try {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
restTemplate = new RestTemplate(requestFactory);
} catch (Exception e) {
LogUtil.error(e);
}
}
public AbstractIssuePlatform(IssuesRequest issuesRequest) {
this();
this.testCaseId = issuesRequest.getTestCaseId();
@ -119,7 +89,6 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
this.testCaseIssueService = CommonBeanFactory.getBean(TestCaseIssueService.class);
this.customFieldIssuesService = CommonBeanFactory.getBean(CustomFieldIssuesService.class);
this.customFieldService = CommonBeanFactory.getBean(CustomFieldService.class);
this.restTemplateIgnoreSSL = restTemplate;
}
protected String getPlatformConfig(String platform) {

View File

@ -30,6 +30,8 @@ public abstract class BaseClient {
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom()
// 可以支持设置系统代理
.useSystemProperties()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();