|
|
|
@ -17,10 +17,10 @@
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.plugin.alert.http; |
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
|
import org.apache.dolphinscheduler.alert.api.AlertResult; |
|
|
|
|
import org.apache.dolphinscheduler.spi.utils.JSONUtils; |
|
|
|
|
import org.apache.dolphinscheduler.spi.utils.StringUtils; |
|
|
|
|
|
|
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
@ -30,14 +30,15 @@ import org.apache.http.entity.StringEntity;
|
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
|
import org.apache.http.impl.client.HttpClientBuilder; |
|
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
|
import java.net.MalformedURLException; |
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.net.URISyntaxException; |
|
|
|
|
import java.net.URL; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
public final class HttpSender { |
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(HttpSender.class); |
|
|
|
@ -71,7 +72,13 @@ public final class HttpSender {
|
|
|
|
|
|
|
|
|
|
AlertResult alertResult = new AlertResult(); |
|
|
|
|
|
|
|
|
|
createHttpRequest(msg); |
|
|
|
|
try { |
|
|
|
|
createHttpRequest(msg); |
|
|
|
|
} catch (MalformedURLException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} catch (URISyntaxException e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (httpRequest == null) { |
|
|
|
|
alertResult.setStatus("false"); |
|
|
|
@ -95,7 +102,7 @@ public final class HttpSender {
|
|
|
|
|
return alertResult; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createHttpRequest(String msg) { |
|
|
|
|
private void createHttpRequest(String msg) throws MalformedURLException, URISyntaxException { |
|
|
|
|
if (REQUEST_TYPE_POST.equals(requestType)) { |
|
|
|
|
httpRequest = new HttpPost(url); |
|
|
|
|
setHeader(); |
|
|
|
@ -104,7 +111,10 @@ public final class HttpSender {
|
|
|
|
|
} else if (REQUEST_TYPE_GET.equals(requestType)) { |
|
|
|
|
//GET request add param in url
|
|
|
|
|
setMsgInUrl(msg); |
|
|
|
|
httpRequest = new HttpGet(url); |
|
|
|
|
URL unencodeUrl = new URL(url); |
|
|
|
|
URI uri = new URI(unencodeUrl.getProtocol(), unencodeUrl.getHost(), unencodeUrl.getPath(), unencodeUrl.getQuery(), null); |
|
|
|
|
|
|
|
|
|
httpRequest = new HttpGet(uri); |
|
|
|
|
setHeader(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|