This is an automated email from the ASF dual-hosted git repository.
jinyleechina pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 3c71fb05f6 fix(dolphinscheduler-alert): fix create http request error
(#14793)
3c71fb05f6 is described below
commit 3c71fb05f6b64a588ab19df7e96aaef3081e5451
Author: Hunter <[email protected]>
AuthorDate: Sat Sep 9 16:39:27 2023 +0800
fix(dolphinscheduler-alert): fix create http request error (#14793)
request type should use equalsIgnoreCase to equal,msg should add
URLEncoder.encode
Co-authored-by: hunter-cloud09 <[email protected]>
Co-authored-by: Aaron Wang <[email protected]>
Co-authored-by: JinYong Li <[email protected]>
---
.../dolphinscheduler/plugin/alert/http/HttpSender.java | 12 +++++++++---
1 file changed, 9 insertions(+), 3 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 4c0dda1af4..9aeb7ab3c9 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
@@ -32,10 +32,12 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
@@ -111,12 +113,12 @@ public final class HttpSender {
}
private void createHttpRequest(String msg) throws MalformedURLException,
URISyntaxException {
- if (REQUEST_TYPE_POST.equals(requestType)) {
+ if (REQUEST_TYPE_POST.equalsIgnoreCase(requestType)) {
httpRequest = new HttpPost(url);
setHeader();
// POST request add param in request body
setMsgInRequestBody(msg);
- } else if (REQUEST_TYPE_GET.equals(requestType)) {
+ } else if (REQUEST_TYPE_GET.equalsIgnoreCase(requestType)) {
// GET request add param in url
setMsgInUrl(msg);
URL unencodeUrl = new URL(url);
@@ -139,7 +141,11 @@ public final class HttpSender {
if (!url.contains(URL_SPLICE_CHAR)) {
type = URL_SPLICE_CHAR;
}
- url = String.format("%s%s%s=%s", url, type, contentField, msg);
+ try {
+ url = String.format("%s%s%s=%s", url, type, contentField,
URLEncoder.encode(msg, DEFAULT_CHARSET));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
}
}