correct post body for http alert plugin (#11946)
This commit is contained in:
parent
2a373be8eb
commit
6021c228a1
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue