fix: 修正http 请求连接 使用后未关闭,导致连接池满的问题
diff --git a/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/HttpUtils.java b/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/HttpUtils.java
index d6e18d6..c8fbc0f 100644
--- a/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/HttpUtils.java
+++ b/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/HttpUtils.java
@@ -38,8 +38,10 @@
     private static final int MAX_CONNECTIONS = 200;
     private static final int MAX_CONNECTIONS_PER_ROUTE = 20;
 
-    private static final HttpClient HTTP_CLIENT = HttpClientBuilder.create().setMaxConnTotal(MAX_CONNECTIONS)
-            .setMaxConnPerRoute(MAX_CONNECTIONS_PER_ROUTE).build();
+    private static final HttpClient HTTP_CLIENT = HttpClientBuilder.create()
+        .setMaxConnTotal(MAX_CONNECTIONS)
+        .setMaxConnPerRoute(MAX_CONNECTIONS_PER_ROUTE)
+        .build();
 
     /**
      * Execute http response.
diff --git a/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/PoaUtil.java b/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/PoaUtil.java
index 41f44d6..18ae8bc 100644
--- a/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/PoaUtil.java
+++ b/thirdparty-agent/thirdparty-poa/src/main/java/com/supwisdom/institute/backend/thirdparty/poa/PoaUtil.java
@@ -28,9 +28,13 @@
   public static void main(String[] args) {
     
     PoaUtil.poaServerUrl = "https://poa.supwisdom.com";
-    PoaUtil.clientId = "nV8US9uAdFQ0ovuYpFOloXtFkME=";
-    PoaUtil.clientSecret = "dDgZAzuNnOjfsbm8iDohyVCXBU1GwImeMsmkJzjyGh8=";
-    PoaUtil.scope = "user:v1:readUser,user:v1:readOrganization,user:v1:readGroup,user:v1:readLabel,authz:v1:readRole";
+//    PoaUtil.clientId = "nV8US9uAdFQ0ovuYpFOloXtFkME=";
+//    PoaUtil.clientSecret = "dDgZAzuNnOjfsbm8iDohyVCXBU1GwImeMsmkJzjyGh8=";
+//    PoaUtil.scope = "user:v1:readUser,user:v1:readOrganization,user:v1:readGroup,user:v1:readLabel,authz:v1:readRole";
+    
+    PoaUtil.clientId = "RYMmw6ViBOKN0YXyDOtuUc3KHtU=";
+    PoaUtil.clientSecret = "LLIkEPSzQO5ayjc_rRzdaWG87sz4ofkJwK9UtmAzv1U=";
+    PoaUtil.scope = "user:v1:readUser,user:v1:readOrganization,user:v1:readGroup,user:v1:readLabel";
     
     //JSONObject accessTokenObject = PoaUtil.getAccessToken("https://poa.supwisdom.com", "tikgr8E6vfcGDXVSG5Vs-00XJoQ=", "wZugRIydkt9lQqJyi7lco-x8wZyyreb41WC_ioj8g-I=", "personalSecurityCenterSa:v1:admin");
     JSONObject accessTokenObject = PoaUtil.getAccessTokenObject();
@@ -39,12 +43,22 @@
     String accessToken = accessTokenObject.getString("access_token");
     PoaUtil.accessToken = accessToken;
     
-    JSONObject jsonObject = PoaUtil.loadUserInfoByAccountName("https://poa.supwisdom.com/apis/user/v1", "smartadmin");
-    System.out.println(jsonObject.toJSONString());
+    for(int i=0;i<100;i++) {
+      new Thread(new Runnable() {
+
+        @Override
+        public void run() {
+          JSONObject jsonObject = PoaUtil.loadUserInfoByAccountName("https://poa.supwisdom.com/apis/user/v1", "smartadmin");
+          System.out.println(":::"+jsonObject.toJSONString());
+        }
+        
+      }).start();;
+      
+      
+    }
   }
   
   
-
   @Autowired(required = false)
   private DistributedLockHandler distributedLockHandler;
   
@@ -198,8 +212,10 @@
 
     int retry = 0;
     while(retry < 3) {
+      
+      HttpResponse httpResponse = null;
       try{
-        HttpResponse httpResponse = HttpUtils.execute(tokenUrl, "POST", null, null, new HashMap<String, Object>(), headers, formData);
+        httpResponse = HttpUtils.execute(tokenUrl, "POST", null, null, new HashMap<String, Object>(), headers, formData);
         /**
          * {
          *   "access_token": "0loVdVN4AqPIbStZmkvtkw==",
@@ -231,6 +247,8 @@
       } catch (Exception e) {
         // 未知异常时,重试
         log.error("Get access_token by [{}] from poa excption: ", clientId, e);
+      } finally {
+        HttpUtils.close(httpResponse);
       }
 
     }
@@ -279,14 +297,19 @@
     headers.put(HttpHeaders.AUTHORIZATION, "Bearer "+PoaUtil.getAccessToken());
     log.debug("{}", headers);
     
-    HttpResponse httpResponse = HttpUtils.execute(url, "GET", parameters, headers);
-    
-    JSONObject resultJsonObject = parseJSONObject(httpResponse);
-    if (resultJsonObject != null) {
-      if (!resultJsonObject.containsKey("error")) {
-        // XXX: 根据API响应数据,须修改为 只返回实际的 data 数据
-        return resultJsonObject;
+    HttpResponse httpResponse = null;
+    try {
+      httpResponse = HttpUtils.execute(url, "GET", parameters, headers);
+      
+      JSONObject resultJsonObject = parseJSONObject(httpResponse);
+      if (resultJsonObject != null) {
+        if (!resultJsonObject.containsKey("error")) {
+          // XXX: 根据API响应数据,须修改为 只返回实际的 data 数据
+          return resultJsonObject;
+        }
       }
+    } finally {
+      HttpUtils.close(httpResponse);
     }
     
     return null;
@@ -305,14 +328,19 @@
     headers.put(HttpHeaders.AUTHORIZATION, "Bearer "+PoaUtil.getAccessToken());
     log.debug("{}", headers);
     
-    HttpResponse httpResponse = HttpUtils.execute(url, "GET", parameters, headers);
+    HttpResponse httpResponse = null;
+    try {
+      httpResponse = HttpUtils.execute(url, "GET", parameters, headers);
     
-    JSONObject resultJsonObject = parseJSONObject(httpResponse);
-    if (resultJsonObject != null) {
-      if (!resultJsonObject.containsKey("error")) {
-        // XXX: 根据API响应数据,须修改为 只返回实际的 data 数据
-        return resultJsonObject;
+      JSONObject resultJsonObject = parseJSONObject(httpResponse);
+      if (resultJsonObject != null) {
+        if (!resultJsonObject.containsKey("error")) {
+          // XXX: 根据API响应数据,须修改为 只返回实际的 data 数据
+          return resultJsonObject;
+        }
       }
+    } finally {
+      HttpUtils.close(httpResponse);
     }
     
     return null;