Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import com.fasterxml.jackson.core.type.TypeReference;

@Slf4j
public final class HttpSender {

private Map<String, String> headerParams;
private OkHttpRequestHeaderContentType contentType;
private Map<String, String> bodyParams;
private Map<String, Object> bodyParams;
private HttpRequestMethod requestType;
private int timeout;
private String url;
Expand All @@ -69,7 +71,9 @@ private void paramsValidator(Map<String, String> paramsMap) {

String bodyParamsString = paramsMap.get(HttpAlertConstants.NAME_BODY_PARAMS);
if (StringUtils.isNotBlank(bodyParamsString)) {
bodyParams = JSONUtils.toMap(bodyParamsString);
// bodyParams = JSONUtils.toMap(bodyParamsString);
bodyParams = JSONUtils.parseObject(bodyParamsString, new TypeReference<Map<String, Object>>() {
});
if (bodyParams == null) {
throw new IllegalArgumentException("bodyParams is not a valid json");
}
Expand All @@ -88,9 +92,9 @@ private void paramsValidator(Map<String, String> paramsMap) {
throw new IllegalArgumentException("contentType is not a valid value");
}

timeout = StringUtils.isNotBlank(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))
timeout = (StringUtils.isNotBlank(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))
? Integer.parseInt(paramsMap.get(HttpAlertConstants.NAME_TIMEOUT))
: HttpAlertConstants.DEFAULT_TIMEOUT * 1000;
: HttpAlertConstants.DEFAULT_TIMEOUT) * 1000;
}

public AlertResult send(String msg) {
Expand Down Expand Up @@ -215,8 +219,10 @@ private void setMsgInRequestBody(String msg) {
}

bodyParams.forEach((key, value) -> {
if (value.contains(HttpAlertConstants.MSG_PARAMS)) {
bodyParams.put(key, value.replace(HttpAlertConstants.MSG_PARAMS, msg));

String valueStr = String.valueOf(value);
if (valueStr.contains(HttpAlertConstants.MSG_PARAMS)) {
bodyParams.put(key, valueStr.replace(HttpAlertConstants.MSG_PARAMS, msg));
}
});
}
Expand Down