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

kirs 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 a0a2c91  [FIX-4876]Http alert plugin fix (#4877)
a0a2c91 is described below

commit a0a2c9141bac753391e4cfaface190da845eb382
Author: JuFeng Li <[email protected]>
AuthorDate: Thu Mar 11 22:39:27 2021 +0800

    [FIX-4876]Http alert plugin fix (#4877)
    
    
    * remove header in  httpRequest
    
    * codestyle fix
    
    Co-authored-by: 李巨丰 <[email protected]>
---
 .../dolphinscheduler/plugin/alert/http/HttpSender.java     | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
index 32d3cdb..7b91904 100644
--- 
a/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
+++ 
b/dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
@@ -26,6 +26,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
@@ -110,17 +111,17 @@ public class HttpSender {
     }
 
     private void createHttpRequest(String msg) {
-
         if (REQUEST_TYPE_POST.equals(requestType)) {
             httpRequest = new HttpPost(url);
+            setHeader();
             //POST request add param in request body
             setMsgInRequestBody(msg);
         } else if (REQUEST_TYPE_GET.equals(requestType)) {
             //GET request add param in url
             setMsgInUrl(msg);
             httpRequest = new HttpGet(url);
+            setHeader();
         }
-        setHeader();
     }
 
     /**
@@ -156,11 +157,16 @@ public class HttpSender {
     /**
      * set body params
      */
-    private String setMsgInRequestBody(String msg) {
+    private void setMsgInRequestBody(String msg)  {
         ObjectNode objectNode = JSONUtils.parseObject(bodyParams);
         //set msg content field
         objectNode.put(contentField, msg);
-        return objectNode.toString();
+        try {
+            StringEntity entity = new StringEntity(bodyParams, 
DEFAULT_CHARSET);
+            ((HttpPost)httpRequest).setEntity(entity);
+        } catch (Exception e) {
+            logger.error("send http alert msg  exception : {}", 
e.getMessage());
+        }
     }
 
 }

Reply via email to