Browse Source

fix: 使用内部网址访问developer,不用绕开SSL

DingXiaoYu 2 years ago
parent
commit
3b63067f05

+ 36 - 36
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/HttpServiceImpl.java

@@ -61,39 +61,39 @@ import java.security.cert.X509Certificate;
 public class HttpServiceImpl implements HttpService {
     private final static Logger log = LoggerFactory.getLogger(HttpService.class);
 
-    private static CloseableHttpClient closeableHttpClient;
-    public static CloseableHttpClient createUnsafeHttpClient() {
-        if (closeableHttpClient==null) {
-            try {
-                SSLContext sslContext = SSLContexts.custom()
-                        .loadTrustMaterial(new TrustStrategy() {
-                            @Override
-                            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
-                                return true; // 忽略证书验证
-                            }
-                        })
-                        .build();
-                SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
-
-                RequestConfig requestConfig = RequestConfig.custom()
-                        .setConnectTimeout(6000)                           // 设置连接超时
-                        .setSocketTimeout(12000)                           // 设置读取超时
-                        .setConnectionRequestTimeout(20000)                // 设置从连接池获取连接实例的超时
-                        .build();
-
-                CloseableHttpClient httpClient = HttpClients.custom()
-                        .setSSLSocketFactory(sslConnectionFactory)
-                        .setConnectionManagerShared(true)
-                        .setDefaultRequestConfig(requestConfig)
-                        .build();
-                closeableHttpClient=httpClient;
-            } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
-                e.printStackTrace();
-                return null;
-            }
-        }
-        return closeableHttpClient;
-    }
+//    private static CloseableHttpClient closeableHttpClient;
+//    public static CloseableHttpClient createUnsafeHttpClient() {
+//        if (closeableHttpClient==null) {
+//            try {
+//                SSLContext sslContext = SSLContexts.custom()
+//                        .loadTrustMaterial(new TrustStrategy() {
+//                            @Override
+//                            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+//                                return true; // 忽略证书验证
+//                            }
+//                        })
+//                        .build();
+//                SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
+//
+//                RequestConfig requestConfig = RequestConfig.custom()
+//                        .setConnectTimeout(6000)                           // 设置连接超时
+//                        .setSocketTimeout(12000)                           // 设置读取超时
+//                        .setConnectionRequestTimeout(20000)                // 设置从连接池获取连接实例的超时
+//                        .build();
+//
+//                CloseableHttpClient httpClient = HttpClients.custom()
+//                        .setSSLSocketFactory(sslConnectionFactory)
+//                        .setConnectionManagerShared(true)
+//                        .setDefaultRequestConfig(requestConfig)
+//                        .build();
+//                closeableHttpClient=httpClient;
+//            } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
+//                e.printStackTrace();
+//                return null;
+//            }
+//        }
+//        return closeableHttpClient;
+//    }
 
     @Override
     public String sendPost(String uri, JSONObject requestBody, List<NameValuePair> params, String token) throws Exception {
@@ -109,7 +109,7 @@ public class HttpServiceImpl implements HttpService {
         httpPost.setHeader("Content-Type", "application/json;chartset=UTF-8");
         httpPost.setEntity(new StringEntity(JSON.toJSONString(requestBody), StandardCharsets.UTF_8));
         httpPost.setConfig(RequestConfig.DEFAULT);
-        CloseableHttpClient client = HttpServiceImpl.createUnsafeHttpClient();
+        CloseableHttpClient client = HttpClients.createDefault();
         CloseableHttpResponse response = client.execute(httpPost);
         HttpEntity entity = response.getEntity();
         String result = EntityUtils.toString(entity);
@@ -167,7 +167,7 @@ public class HttpServiceImpl implements HttpService {
         HttpGet httpGet = new HttpGet(completedUri);
         httpGet.setConfig(RequestConfig.DEFAULT);
         httpGet.setHeader("Authorization", token);
-        CloseableHttpClient client = HttpServiceImpl.createUnsafeHttpClient();
+        CloseableHttpClient client = HttpClients.createDefault();
         CloseableHttpResponse response = client.execute(httpGet);
         HttpEntity entity = response.getEntity();
         String result = EntityUtils.toString(entity);
@@ -203,7 +203,7 @@ public class HttpServiceImpl implements HttpService {
         } else {
             completedUri = uri;
         }
-        CloseableHttpClient httpClient = HttpServiceImpl.createUnsafeHttpClient();
+        CloseableHttpClient httpClient = HttpClients.createDefault();
         HttpPut httpPut = new HttpPut(completedUri);
         if (token != null) {
             httpPut.setHeader("Authorization", token);

+ 6 - 2
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/subsystem/DevcloudServiceImpl.java

@@ -11,6 +11,7 @@ import org.apache.http.NameValuePair;
 import org.apache.http.message.BasicNameValuePair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -24,8 +25,11 @@ import java.util.List;
 public class DevcloudServiceImpl implements DevcloudService {
     private final static Logger log = LoggerFactory.getLogger(DevcloudServiceImpl.class);
 
-    private final String devcloudUri = "https://devcloud-server.internal-paas.seec.seecoder.cn";
-    private final String seecoderGitlabServerUri = "https://seecoder-gitlab-server.internal-paas.seec.seecoder.cn";
+    @Value("${seec.developer.url}")
+    private String devcloudUri;
+
+    @Value("${seec.gitlab.host}")
+    private String seecoderGitlabServerUri;
     private final HttpService httpService;
 
     public DevcloudServiceImpl(HttpService httpService) {this.httpService = httpService;}