Browse Source

[Alert] [HTTP Plugin] Lose HTTP port (#14341)

3.2.1-prepare
旺阳 1 year ago committed by GitHub
parent
commit
c1a6790514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
  2. 10
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/test/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSenderTest.java

6
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 // GET request add param in url
setMsgInUrl(msg); setMsgInUrl(msg);
URL unencodeUrl = new URL(url); 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); unencodeUrl.getQuery(), null);
httpRequest = new HttpGet(uri); httpRequest = new HttpGet(uri);
@ -175,4 +175,8 @@ public final class HttpSender {
log.error("send http alert msg exception : {}", e.getMessage()); log.error("send http alert msg exception : {}", e.getMessage());
} }
} }
public String getRequestUrl() {
return httpRequest.getURI().toString();
}
} }

10
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 @Test
public void sendTest() throws IOException { public void sendTest() throws IOException {
Map<String, String> paramsMap = new HashMap<>(); Map<String, String> paramsMap = new HashMap<>();
paramsMap.put(HttpAlertConstants.NAME_URL, "http://www.dolphinscheduler-not-exists-web.com"); String url = "https://www.dolphinscheduler-not-exists-web.com:12345";
paramsMap.put(HttpAlertConstants.NAME_REQUEST_TYPE, "POST"); 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_HEADER_PARAMS, "{\"Content-Type\":\"application/json\"}");
paramsMap.put(HttpAlertConstants.NAME_BODY_PARAMS, "{\"number\":\"123456\"}"); 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)); HttpSender httpSender = spy(new HttpSender(paramsMap));
doReturn("success").when(httpSender).getResponseString(any()); doReturn("success").when(httpSender).getResponseString(any());
AlertResult alertResult = httpSender.send("Fault tolerance warning"); AlertResult alertResult = httpSender.send("Fault tolerance warning");
Assertions.assertEquals("true", alertResult.getStatus()); Assertions.assertEquals("true", alertResult.getStatus());
Assertions.assertTrue(httpSender.getRequestUrl().contains(url));
Assertions.assertTrue(httpSender.getRequestUrl().contains(contentField));
} }
} }

Loading…
Cancel
Save