From 6021c228a1261a45ba8d02606f7132cd0a9b4c25 Mon Sep 17 00:00:00 2001 From: Daniel Y Date: Mon, 19 Sep 2022 14:42:19 +0800 Subject: [PATCH] correct post body for http alert plugin (#11946) --- .../apache/dolphinscheduler/plugin/alert/http/HttpSender.java | 2 +- .../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 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()); } }