samz406 commented on a change in pull request #4877:
URL:
https://github.com/apache/incubator-dolphinscheduler/pull/4877#discussion_r583551813
##########
File path:
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
##########
@@ -156,11 +160,16 @@ private void setHeader() {
/**
* set body params
*/
- private String setMsgInRequestBody(String msg) {
+ private void setMsgInRequestBody(String msg) {
ObjectNode objectNode = JSONUtils.parseObject(bodyParams);
//set msg content field
objectNode.put(contentField, msg);
- return objectNode.toString();
+ try {
+ HeaderElement element =
httpRequest.getHeaders("Content-Type")[0].getElements()[0];
Review comment:
The Content-Type in the header is not required. The header parameter
here is provided by the callee; the body parameter is first designed in Json
format. Therefore, it is not necessary to obtain the header as a judgment.
Here, contentField is the parameter name. For example, when calling some
manufacturers' SMS interface, the parameter name of the SMS content is
specific, so it is made to fill in manually.
header中Content-Type 不是必填项,这里的header
参数是被调用方提供的;这里最先设计body参数都是Json格式。所以可以不用获取header作为判断,这里contentField
是参数名称,比如调用有些厂商短信接口,短信内容参数名是特定的,所以这里做成手动填写。msg 参数就是告警内容
##########
File path:
dolphinscheduler-alert-plugin/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java
##########
@@ -110,17 +114,17 @@ public AlertResult send(String msg) {
}
private void createHttpRequest(String msg) {
-
if (REQUEST_TYPE_POST.equals(requestType)) {
httpRequest = new HttpPost(url);
+ setHeader();
//POST request add param in request body
setMsgInRequestBody(msg);
Review comment:
I think it can be changed as follows:
我觉得可以改为如下:
String bodyParams = setMsgInRequestBody(msg);
StringEntity entity = new StringEntity(bodyParams, DEFAULT_CHARSET);
((HttpPost)httpRequest).setEntity(entity);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]