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 bdf6f0548e
commit 6ff14735dc
2 changed files with 2 additions and 32 deletions

View File

@ -26,24 +26,16 @@ import io.metersphere.track.service.IssuesService;
import io.metersphere.track.service.TestCaseIssueService; import io.metersphere.track.service.TestCaseIssueService;
import io.metersphere.track.service.TestCaseService; import io.metersphere.track.service.TestCaseService;
import org.apache.commons.lang3.StringUtils; 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.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.safety.Whitelist; import org.jsoup.safety.Whitelist;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.io.File; import java.io.File;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.security.cert.X509Certificate;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -52,8 +44,6 @@ import java.util.stream.Collectors;
public abstract class AbstractIssuePlatform implements IssuesPlatform { public abstract class AbstractIssuePlatform implements IssuesPlatform {
private static RestTemplate restTemplate;
protected IntegrationService integrationService; protected IntegrationService integrationService;
protected TestCaseIssueService testCaseIssueService; protected TestCaseIssueService testCaseIssueService;
protected TestCaseIssuesMapper testCaseIssuesMapper; protected TestCaseIssuesMapper testCaseIssuesMapper;
@ -62,7 +52,6 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
protected IssuesMapper issuesMapper; protected IssuesMapper issuesMapper;
protected ExtIssuesMapper extIssuesMapper; protected ExtIssuesMapper extIssuesMapper;
protected ResourceService resourceService; protected ResourceService resourceService;
protected RestTemplate restTemplateIgnoreSSL;
protected UserService userService; protected UserService userService;
protected ProjectMapper projectMapper; protected ProjectMapper projectMapper;
protected String testCaseId; protected String testCaseId;
@ -73,30 +62,10 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
protected String defaultCustomFields; protected String defaultCustomFields;
protected boolean isThirdPartTemplate; protected boolean isThirdPartTemplate;
public String getKey() { public String getKey() {
return key; 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) { public AbstractIssuePlatform(IssuesRequest issuesRequest) {
this(); this();
this.testCaseId = issuesRequest.getTestCaseId(); this.testCaseId = issuesRequest.getTestCaseId();
@ -116,7 +85,6 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
this.extIssuesMapper = CommonBeanFactory.getBean(ExtIssuesMapper.class); this.extIssuesMapper = CommonBeanFactory.getBean(ExtIssuesMapper.class);
this.resourceService = CommonBeanFactory.getBean(ResourceService.class); this.resourceService = CommonBeanFactory.getBean(ResourceService.class);
this.testCaseIssueService = CommonBeanFactory.getBean(TestCaseIssueService.class); this.testCaseIssueService = CommonBeanFactory.getBean(TestCaseIssueService.class);
this.restTemplateIgnoreSSL = restTemplate;
} }
protected String getPlatformConfig(String platform) { protected String getPlatformConfig(String platform) {

View File

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