summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwanghao <[email protected]>2022-08-11 15:16:31 +0800
committerwanghao <[email protected]>2022-08-11 15:16:31 +0800
commitbb29a4969565d0959e819aa8bf0e749828366598 (patch)
tree8a30395025ac8db148f98c5f762b24b414dc622c
parent1419617b6d9cfa11c5f727a2dec7e92a05a505a4 (diff)
parent2f86c334cbe38f1af8ff4312573593d3c8e3d928 (diff)
Merge branch 'develop' of https://git.mesalab.cn/galaxy/galaxy-qgw-service into develop
-rw-r--r--config/nacos/config/fixed-127.0.0.1_8848-tsg_nacos/data/config-data-tenant/tsg/Galaxy/galaxy-qgw-service.yml4
-rw-r--r--src/main/java/com/mesalab/knowledge/service/impl/KnowledgeBaseServiceImpl.java7
-rw-r--r--src/main/java/com/mesalab/qgw/service/impl/HttpClientService.java85
3 files changed, 76 insertions, 20 deletions
diff --git a/config/nacos/config/fixed-127.0.0.1_8848-tsg_nacos/data/config-data-tenant/tsg/Galaxy/galaxy-qgw-service.yml b/config/nacos/config/fixed-127.0.0.1_8848-tsg_nacos/data/config-data-tenant/tsg/Galaxy/galaxy-qgw-service.yml
index 29f90c06..03f9fbf5 100644
--- a/config/nacos/config/fixed-127.0.0.1_8848-tsg_nacos/data/config-data-tenant/tsg/Galaxy/galaxy-qgw-service.yml
+++ b/config/nacos/config/fixed-127.0.0.1_8848-tsg_nacos/data/config-data-tenant/tsg/Galaxy/galaxy-qgw-service.yml
@@ -148,8 +148,8 @@ task:
queueCapacity: 1000
## hos cfg
hos:
- uri: http://192.168.44.12:9098/hos/
- bucket: knowledge_base_hos_bucket/
+ uri: http://192.168.44.12:9098/hos
+ bucket: /knowledge_base_hos_bucket
token: c21f969b5f03d33d43e04f8f136e7682
## knowledge value 格式 name:版本
knowledge:
diff --git a/src/main/java/com/mesalab/knowledge/service/impl/KnowledgeBaseServiceImpl.java b/src/main/java/com/mesalab/knowledge/service/impl/KnowledgeBaseServiceImpl.java
index f679fe58..154a8977 100644
--- a/src/main/java/com/mesalab/knowledge/service/impl/KnowledgeBaseServiceImpl.java
+++ b/src/main/java/com/mesalab/knowledge/service/impl/KnowledgeBaseServiceImpl.java
@@ -26,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.*;
+import java.util.stream.Collectors;
@Service
@@ -65,7 +66,9 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
@Override
public BaseResult knowledgeQuery() {
- return BaseResultGenerator.success(queryKnowledgeBaseList());
+ List<KnowledgeBase> knowledgeBaseList = queryKnowledgeBaseList();
+ List<KnowledgeBase> list = knowledgeBaseList.stream().sorted(Comparator.comparing(KnowledgeBase::getUpdateTime).reversed()).collect(Collectors.toList());
+ return BaseResultGenerator.success(list);
}
@Override
@@ -198,7 +201,7 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
Header header = new BasicHeader("token", hosConfig.getToken());
String assessmentFile = null;
try {
- assessmentFile = uri.concat(bucket).concat(Base64.getEncoder().encodeToString(id.getBytes("UTF-8")));
+ assessmentFile = uri.concat(bucket).concat("/").concat(Base64.getEncoder().encodeToString(id.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
log.error(e);
}
diff --git a/src/main/java/com/mesalab/qgw/service/impl/HttpClientService.java b/src/main/java/com/mesalab/qgw/service/impl/HttpClientService.java
index 14c4213d..3a05408e 100644
--- a/src/main/java/com/mesalab/qgw/service/impl/HttpClientService.java
+++ b/src/main/java/com/mesalab/qgw/service/impl/HttpClientService.java
@@ -5,6 +5,7 @@ import cn.hutool.log.LogFactory;
import com.google.common.collect.Maps;
import com.mesalab.common.enums.ResultStatusEnum;
import com.mesalab.common.exception.BusinessException;
+import com.mesalab.common.utils.SpringContextUtil;
import com.mesalab.qgw.model.api.HttpConfig;
import com.zdjizhi.utils.StringUtil;
import org.apache.commons.io.IOUtils;
@@ -14,8 +15,14 @@ import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.*;
import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -27,38 +34,84 @@ import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.net.*;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
@Service
public class HttpClientService {
+
private static final Log log = LogFactory.get();
+
@Autowired
private HttpConfig httpConfig;
- //全局连接池对象
- private PoolingHttpClientConnectionManager connectionManager;
+// //全局连接池对象
+// private PoolingHttpClientConnectionManager connectionManager;
+
+// /**
+// * 初始化连接池信息
+// */
+// @PostConstruct
+// public void initConnectionManager() {
+// if (connectionManager == null) {
+// connectionManager = new PoolingHttpClientConnectionManager();
+// // 整个连接池最大连接数
+// connectionManager.setMaxTotal(httpConfig.getMaxConnectionNum());
+// // 每路由最大连接数,默认值是2
+// connectionManager.setDefaultMaxPerRoute(httpConfig.getMaxPerRoute());
+// }
+// log.info("Initializing PoolingHttpClientConnectionManager Complete");
+// }
/**
- * 初始化连接池信息
+ * 在调用SSL之前需要重写验证方法,取消检测SSL
+ * 创建ConnectionManager,添加Connection配置信息
+ *
+ * @return HttpClient 支持https
*/
- @PostConstruct
- public void initConnectionManager() {
- if (connectionManager == null) {
- connectionManager = new PoolingHttpClientConnectionManager();
- // 整个连接池最大连接数
- connectionManager.setMaxTotal(httpConfig.getMaxConnectionNum());
- // 每路由最大连接数,默认值是2
- connectionManager.setDefaultMaxPerRoute(httpConfig.getMaxPerRoute());
+ private PoolingHttpClientConnectionManager getSslClientManager() {
+ try {
+ // 在调用SSL之前需要重写验证方法,取消检测SSL
+ X509TrustManager trustManager = new X509TrustManager() {
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ @Override
+ public void checkClientTrusted(X509Certificate[] xcs, String str) {
+ }
+ @Override
+ public void checkServerTrusted(X509Certificate[] xcs, String str) {
+ }
+ };
+ SSLContext ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
+ ctx.init(null, new TrustManager[]{trustManager}, null);
+ SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
+ Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
+ .register("http", PlainConnectionSocketFactory.INSTANCE)
+ .register("https", socketFactory).build();
+ // 创建ConnectionManager,添加Connection配置信息
+ PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
+ // 设置最大连接数
+ connManager.setMaxTotal(httpConfig.getMaxConnectionNum());
+ // 设置每个连接的路由数
+ connManager.setDefaultMaxPerRoute(httpConfig.getMaxPerRoute());
+ return connManager;
+ } catch (KeyManagementException e) {
+ log.error(e);
+ throw new BusinessException(e.getMessage());
+ } catch (NoSuchAlgorithmException e) {
+ log.error(e);
+ throw new BusinessException(e.getMessage());
}
- log.info("Initializing PoolingHttpClientConnectionManager Complete");
}
/**
@@ -144,7 +197,7 @@ public class HttpClientService {
.setRetryHandler(retry)
.setKeepAliveStrategy(myStrategy)
// 配置连接池管理对象
- .setConnectionManager(connectionManager)
+ .setConnectionManager(getSslClientManager())
.build();
}