You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ji...@apache.org on 2022/09/19 06:42:26 UTC

[dolphinscheduler] branch 2.0.7-prepare updated: correct post body for http alert plugin (#11946)

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

jinyleechina pushed a commit to branch 2.0.7-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/2.0.7-prepare by this push:
     new 6021c228a1 correct post body for http alert plugin (#11946)
6021c228a1 is described below

commit 6021c228a1261a45ba8d02606f7132cd0a9b4c25
Author: Daniel Y <da...@gmail.com>
AuthorDate: Mon Sep 19 14:42:19 2022 +0800

    correct post body for http alert plugin (#11946)
---
 .../java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java | 2 +-
 .../org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
index a1b0923013..a04437bb8c 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
@@ -143,7 +143,7 @@ public final class HttpSender {
         //set msg content field
         objectNode.put(contentField, msg);
         try {
-            StringEntity entity = new StringEntity(bodyParams, DEFAULT_CHARSET);
+            StringEntity entity = new StringEntity(JSONUtils.toJsonString(objectNode), DEFAULT_CHARSET);
             ((HttpPost) httpRequest).setEntity(entity);
         } catch (Exception e) {
             log.error("send http alert msg  exception : {}", e.getMessage());
diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java
index 8628f0c55d..fa0dfe80f1 100644
--- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java
+++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java
@@ -29,13 +29,14 @@ public class HttpSenderTest {
     @Test
     public void sendTest() {
         Map<String, String> paramsMap = new HashMap<>();
-        paramsMap.put(HttpAlertConstants.URL, "http://www.baidu.com");
+        paramsMap.put(HttpAlertConstants.URL, "https://httpbin.org/post");
         paramsMap.put(HttpAlertConstants.REQUEST_TYPE, "POST");
         paramsMap.put(HttpAlertConstants.HEADER_PARAMS, "{\"Content-Type\":\"application/json\"}");
         paramsMap.put(HttpAlertConstants.BODY_PARAMS, "{\"number\":\"13457654323\"}");
         paramsMap.put(HttpAlertConstants.CONTENT_FIELD, "content");
         HttpSender httpSender = new HttpSender(paramsMap);
         AlertResult alertResult = httpSender.send("Fault tolerance warning");
+        Assert.assertTrue(alertResult.getMessage().contains("\"content\": \"Fault tolerance warning\""));
         Assert.assertEquals("true", alertResult.getStatus());
     }
 }