From c1a67905149a1d791ec23dca477bc59c08c4f607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=BA=E9=98=B3?= Date: Wed, 14 Jun 2023 17:38:58 +0800 Subject: [PATCH] [Alert] [HTTP Plugin] Lose HTTP port (#14341) --- .../dolphinscheduler/plugin/alert/http/HttpSender.java | 6 +++++- .../plugin/alert/http/HttpSenderTest.java | 10 +++++++--- 2 files changed, 12 insertions(+), 4 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 ab4189bd13..4c0dda1af4 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 @@ -120,7 +120,7 @@ public final class HttpSender { // GET request add param in url setMsgInUrl(msg); URL unencodeUrl = new URL(url); - URI uri = new URI(unencodeUrl.getProtocol(), unencodeUrl.getHost(), unencodeUrl.getPath(), + URI uri = new URI(unencodeUrl.getProtocol(), unencodeUrl.getAuthority(), unencodeUrl.getPath(), unencodeUrl.getQuery(), null); httpRequest = new HttpGet(uri); @@ -175,4 +175,8 @@ public final class HttpSender { log.error("send http alert msg exception : {}", e.getMessage()); } } + + public String getRequestUrl() { + return httpRequest.getURI().toString(); + } } 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 73473876f6..9f4e017b86 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 @@ -35,15 +35,19 @@ public class HttpSenderTest { @Test public void sendTest() throws IOException { Map paramsMap = new HashMap<>(); - paramsMap.put(HttpAlertConstants.NAME_URL, "http://www.dolphinscheduler-not-exists-web.com"); - paramsMap.put(HttpAlertConstants.NAME_REQUEST_TYPE, "POST"); + String url = "https://www.dolphinscheduler-not-exists-web.com:12345"; + String contentField = "content"; + paramsMap.put(HttpAlertConstants.NAME_URL, url); + paramsMap.put(HttpAlertConstants.NAME_REQUEST_TYPE, "GET"); paramsMap.put(HttpAlertConstants.NAME_HEADER_PARAMS, "{\"Content-Type\":\"application/json\"}"); paramsMap.put(HttpAlertConstants.NAME_BODY_PARAMS, "{\"number\":\"123456\"}"); - paramsMap.put(HttpAlertConstants.NAME_CONTENT_FIELD, "content"); + paramsMap.put(HttpAlertConstants.NAME_CONTENT_FIELD, contentField); HttpSender httpSender = spy(new HttpSender(paramsMap)); doReturn("success").when(httpSender).getResponseString(any()); AlertResult alertResult = httpSender.send("Fault tolerance warning"); Assertions.assertEquals("true", alertResult.getStatus()); + Assertions.assertTrue(httpSender.getRequestUrl().contains(url)); + Assertions.assertTrue(httpSender.getRequestUrl().contains(contentField)); } }