This is an automated email from the ASF dual-hosted git repository.

journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new dad7572      fix bug (#1633)
dad7572 is described below

commit dad75727ff939b7f0d73acdafe0251921deac50e
Author: Jave-Chen <[email protected]>
AuthorDate: Mon Dec 30 10:28:47 2019 +0800

        fix bug (#1633)
    
    
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
          
https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&issues=AW9PvkP_YzPBRjkobY7y&open=AW9PvkP_YzPBRjkobY7y
          
https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&issues=AW9PvkP_YzPBRjkobY7z&open=AW9PvkP_YzPBRjkobY7z
    
        
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
          
https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&issues=AW9PvkRwYzPBRjkobY87&open=AW9PvkRwYzPBRjkobY87
---
 .../apache/dolphinscheduler/alert/AlertServer.java | 11 ++---
 .../alert/utils/EnterpriseWeChatUtils.java         | 53 +++++++++++++---------
 2 files changed, 35 insertions(+), 29 deletions(-)

diff --git 
a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
 
b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
index ee38f3d..a41498e 100644
--- 
a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
+++ 
b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
@@ -39,19 +39,15 @@ public class AlertServer {
 
     private AlertSender alertSender;
 
-    private static volatile AlertServer instance;
+    private static AlertServer instance;
 
     public AlertServer() {
 
     }
 
-    public static AlertServer getInstance(){
+    public synchronized static AlertServer getInstance(){
         if (null == instance) {
-            synchronized (AlertServer.class) {
-                if(null == instance) {
-                    instance = new AlertServer();
-                }
-            }
+            instance = new AlertServer();
         }
         return instance;
     }
@@ -63,6 +59,7 @@ public class AlertServer {
                 Thread.sleep(Constants.ALERT_SCAN_INTERVEL);
             } catch (InterruptedException e) {
                 logger.error(e.getMessage(),e);
+                Thread.currentThread().interrupt();
             }
             List<Alert> alerts = alertDao.listWaitExecutionAlert();
             alertSender = new AlertSender(alerts, alertDao);
diff --git 
a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
 
b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
index a11d37f..15e7e18 100644
--- 
a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
+++ 
b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
@@ -86,20 +86,24 @@ public class EnterpriseWeChatUtils {
         String resp;
 
         CloseableHttpClient httpClient = HttpClients.createDefault();
-        HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace);
-        CloseableHttpResponse response = httpClient.execute(httpGet);
         try {
-            HttpEntity entity = response.getEntity();
-            resp = EntityUtils.toString(entity, Constants.UTF_8);
-            EntityUtils.consume(entity);
+            HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace);
+            CloseableHttpResponse response = httpClient.execute(httpGet);
+            try {
+                HttpEntity entity = response.getEntity();
+                resp = EntityUtils.toString(entity, Constants.UTF_8);
+                EntityUtils.consume(entity);
+            } finally {
+                response.close();
+            }
+
+            Map<String, Object> map = JSON.parseObject(resp,
+                    new TypeToken<Map<String, Object>>() {
+                    }.getType());
+            return map.get("access_token").toString();
         } finally {
-            response.close();
+            httpClient.close();
         }
-
-        Map<String, Object> map = JSON.parseObject(resp,
-                new TypeToken<Map<String, Object>>() {
-                }.getType());
-        return map.get("access_token").toString();
     }
 
     /**
@@ -167,20 +171,25 @@ public class EnterpriseWeChatUtils {
     public static String sendEnterpriseWeChat(String charset, String data, 
String token) throws IOException {
         String enterpriseWeChatPushUrlReplace = 
enterpriseWeChatPushUrl.replaceAll("\\$token", token);
 
-        CloseableHttpClient httpclient = HttpClients.createDefault();
-        HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace);
-        httpPost.setEntity(new StringEntity(data, charset));
-        CloseableHttpResponse response = httpclient.execute(httpPost);
-        String resp;
+        CloseableHttpClient httpClient = HttpClients.createDefault();
         try {
-            HttpEntity entity = response.getEntity();
-            resp = EntityUtils.toString(entity, charset);
-            EntityUtils.consume(entity);
+            HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace);
+            httpPost.setEntity(new StringEntity(data, charset));
+            CloseableHttpResponse response = httpClient.execute(httpPost);
+            String resp;
+            try {
+                HttpEntity entity = response.getEntity();
+                resp = EntityUtils.toString(entity, charset);
+                EntityUtils.consume(entity);
+            } finally {
+                response.close();
+            }
+            logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", 
+                enterpriseWeChatPushUrl, data, resp);
+            return resp;
         } finally {
-            response.close();
+            httpClient.close();
         }
-        logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", 
enterpriseWeChatPushUrl, data, resp);
-        return resp;
     }
 
     /**

Reply via email to