|
@@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
@@ -32,7 +33,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URI;
|
|
@@ -63,6 +63,7 @@ public final class HttpSender {
|
|
|
private final String bodyParams;
|
|
|
private final String contentField;
|
|
|
private final String requestType;
|
|
|
+ private final int timeout;
|
|
|
private String url;
|
|
|
private HttpRequestBase httpRequest;
|
|
|
|
|
@@ -73,6 +74,9 @@ public final class HttpSender {
|
|
|
bodyParams = paramsMap.get(HttpAlertConstants.NAME_BODY_PARAMS);
|
|
|
contentField = paramsMap.get(HttpAlertConstants.NAME_CONTENT_FIELD);
|
|
|
requestType = paramsMap.get(HttpAlertConstants.NAME_REQUEST_TYPE);
|
|
|
+ timeout = StringUtils.isNotBlank(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))
|
|
|
+ ? Integer.parseInt(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))
|
|
|
+ : HttpAlertConstants.DEFAULT_TIMEOUT;
|
|
|
}
|
|
|
|
|
|
public AlertResult send(String msg) {
|
|
@@ -107,9 +111,17 @@ public final class HttpSender {
|
|
|
return alertResult;
|
|
|
}
|
|
|
|
|
|
- public String getResponseString(HttpRequestBase httpRequest) throws IOException {
|
|
|
- CloseableHttpClient httpClient =
|
|
|
- HttpClients.custom().setRetryHandler(HttpServiceRetryStrategy.retryStrategy).build();
|
|
|
+ public String getResponseString(HttpRequestBase httpRequest) throws Exception {
|
|
|
+
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+ .setConnectTimeout(timeout * 1000)
|
|
|
+ .setConnectionRequestTimeout(timeout * 1000)
|
|
|
+ .setSocketTimeout(timeout * 1000)
|
|
|
+ .build();
|
|
|
+ CloseableHttpClient httpClient = HttpClients.custom()
|
|
|
+ .setDefaultRequestConfig(requestConfig)
|
|
|
+ .setRetryHandler(HttpServiceRetryStrategy.retryStrategy).build();
|
|
|
+
|
|
|
CloseableHttpResponse response = httpClient.execute(httpRequest);
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
return EntityUtils.toString(entity, DEFAULT_CHARSET);
|