ChiangHaosion opened a new issue, #18740: URL: https://github.com/apache/dolphinscheduler/issues/18740
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and found no similar issues. ### What happened The HTTP alert plugin cannot send a request body that contains nested JSON objects/arrays. Any nested value is passed through `String.valueOf(...)`, which yields Java's `Map/List.toString()` (`{content=...}`) instead of JSON, and the result is written back as a String. The receiver therefore gets a JSON *string* where it expects an *object*, and rejects the payload. Body params configured in the alert instance: {"msgtype":"text","text":{"content":"${msg}"}} What is actually sent on the wire: {"msgtype":"text","text":"{content= This is a test alert message form DolphinScheduler}"} `text` became a string, the inner key lost its JSON quoting, and the receiver (WeChat Work robot in my case) fails validation. This is the remaining half of #17912. PR #17911 (3.4.1) changed `bodyParams` from `Map<String, String>` to `Map<String, Object>` so that a nested body can be *saved* without `IllegalArgumentException: bodyParams is not a valid json`, but the very same PR changed `HttpSender#setMsgInRequestBody` to: bodyParams.forEach((key, value) -> { String valueOf = String.valueOf(value); if (valueOf.contains(HttpAlertConstants.MSG_PARAMS)) { bodyParams.put(key, valueOf.replace(HttpAlertConstants.MSG_PARAMS, msg)); } }); so nested values are still flattened at substitution time. Only flat bodies such as `{"msg":"${msg}"}` work today, and no real webhook API (WeChat Work / Feishu / Slack style) accepts a flat body. ### What you expected to happen The JSON structure configured in Body Params should survive the ${msg} substitution, and quoting / escaping should be left to the JSON serializer: {"msgtype":"text","text":{"content":" This is a test alert message form DolphinScheduler"}} Suggested fix: walk the parsed body recursively (Map / List) and replace ${msg} only in string nodes, instead of stringifying top-level values. `OkHttpUtils` already serializes the body map with Jackson, so quotes and newlines inside ${msg} get escaped correctly without any manual escaping. ### How to reproduce 1. Security Config -> Alert Instance -> create an HTTP alert instance: - URL: any receiver that lets you inspect the raw request body, e.g. https://webhook.site/<uuid> (or a WeChat Work robot: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx) - Request Type: POST - Content Type: application/json - Body: {"msgtype":"text","text":{"content":"${msg}"}} 2. Save, then click Test on the instance. 3. Inspect the body the receiver got: it is "text":"{content= ...}" (a string), and WeChat Work answers with a non-zero errcode even though the HTTP status is 200. ### Anything else - Affected request types: POST and PUT (both call setMsgInRequestBody). - Occurs every time the configured body contains a nested object or array. - The failure is silent for receivers that answer HTTP 200 with an error payload: validateResponse only checks the status code, so the log/UI shows "send http alert success". I will file that separately as an improvement. - The request log prints the body via Java Map.toString() ("requestBody: {msgtype=text, text={content=...}}"), which looks almost identical before and after a fix, so it is misleading during troubleshooting. - The docs already promise this works: docs/docs/en/guide/alert/http.md states that ${msg} "can be used in URL, Headers, and Body" with no restriction on nesting. - Related history: #17912 / PR #17911 (parse-level fix only), #16589, #14839. ### Version 3.4.3 ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
