correct post body for http alert plugin (#11946)

This commit is contained in:
Daniel Y 2022-09-19 14:42:19 +08:00 committed by GitHub
parent 2a373be8eb
commit 6021c228a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -143,7 +143,7 @@ public final class HttpSender {
//set msg content field
objectNode.put(contentField, msg);
try {
StringEntity entity = new StringEntity(bodyParams, DEFAULT_CHARSET);
StringEntity entity = new StringEntity(JSONUtils.toJsonString(objectNode), DEFAULT_CHARSET);
((HttpPost) httpRequest).setEntity(entity);
} catch (Exception e) {
log.error("send http alert msg exception : {}", e.getMessage());

View File

@ -29,13 +29,14 @@ public class HttpSenderTest {
@Test
public void sendTest() {
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put(HttpAlertConstants.URL, "http://www.baidu.com");
paramsMap.put(HttpAlertConstants.URL, "https://httpbin.org/post");
paramsMap.put(HttpAlertConstants.REQUEST_TYPE, "POST");
paramsMap.put(HttpAlertConstants.HEADER_PARAMS, "{\"Content-Type\":\"application/json\"}");
paramsMap.put(HttpAlertConstants.BODY_PARAMS, "{\"number\":\"13457654323\"}");
paramsMap.put(HttpAlertConstants.CONTENT_FIELD, "content");
HttpSender httpSender = new HttpSender(paramsMap);
AlertResult alertResult = httpSender.send("Fault tolerance warning");
Assert.assertTrue(alertResult.getMessage().contains("\"content\": \"Fault tolerance warning\""));
Assert.assertEquals("true", alertResult.getStatus());
}
}