You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by zh...@apache.org on 2022/11/09 09:44:13 UTC
[rocketmq-connect] branch master updated: fix: make the rest api for create connectors more robust (#371)
This is an automated email from the ASF dual-hosted git repository.
zhoubo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-connect.git
The following commit(s) were added to refs/heads/master by this push:
new 7cc5aee1 fix: make the rest api for create connectors more robust (#371)
7cc5aee1 is described below
commit 7cc5aee124253fcfaa20e1860b44b277e5577cfc
Author: fireround <ch...@foxmail.com>
AuthorDate: Wed Nov 9 17:44:08 2022 +0800
fix: make the rest api for create connectors more robust (#371)
Co-authored-by: cheng.wen-1 <ch...@yeepay.com>
---
.../apache/rocketmq/connect/runtime/rest/RestHandler.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/rest/RestHandler.java b/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/rest/RestHandler.java
index 07c25993..352c1ef7 100644
--- a/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/rest/RestHandler.java
+++ b/rocketmq-connect-runtime/src/main/java/org/apache/rocketmq/connect/runtime/rest/RestHandler.java
@@ -18,8 +18,10 @@
package org.apache.rocketmq.connect.runtime.rest;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONException;
import io.javalin.Javalin;
import io.javalin.http.Context;
+import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.connect.runtime.common.ConnectKeyValue;
import org.apache.rocketmq.connect.runtime.common.LoggerName;
import org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector;
@@ -134,12 +136,20 @@ public class RestHandler {
} else {
arg = context.req.getParameter("config");
}
- if (arg == null) {
+ if (StringUtils.isBlank(arg)) {
context.json(new ErrorMessage(HttpStatus.BAD_REQUEST_400, "Failed! query param 'config' is required "));
return;
}
log.info("connect config: {}", arg);
- Map keyValue = JSON.parseObject(arg, Map.class);
+
+ Map keyValue;
+ try {
+ keyValue = JSON.parseObject(arg, Map.class);
+ } catch (JSONException e) {
+ context.json(new ErrorMessage(HttpStatus.BAD_REQUEST_400, "Failed! query param 'config' is malformed"));
+ return;
+ }
+
ConnectKeyValue configs = new ConnectKeyValue();
for (Object key : keyValue.keySet()) {
configs.put((String) key, keyValue.get(key).toString());