Aias00 commented on code in PR #6061:
URL: https://github.com/apache/shenyu/pull/6061#discussion_r2218294631
##########
shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/request/RequestConfigHelper.java:
##########
@@ -117,25 +97,86 @@ public boolean isArgsToUrlParam() {
*/
public static String buildPath(final String urlTemplate, final JsonObject
argsPosition,
final JsonObject inputJson) {
- // First, check if the input value is already a complete URL
- for (String key : argsPosition.keySet()) {
- if (inputJson.has(key)) {
- String value = inputJson.get(key).getAsString();
- // If the input value is already a complete URL, return it
directly
- if (value.startsWith("http://") ||
value.startsWith("https://")) {
- return value;
- }
- }
+ // 首先检查输入值是否已经是一个完整的 URL
+ if (isCompleteUrl(argsPosition, inputJson)) {
+ return getCompleteUrl(argsPosition, inputJson);
}
-
+
StringBuilder queryBuilder = new StringBuilder();
-
- // Check if the URL template already contains query parameters
+
+ // 检查 URL 模板中是否已经包含查询参数
boolean hasExistingQuery = urlTemplate.contains("?");
String basePath = hasExistingQuery ? urlTemplate.substring(0,
urlTemplate.indexOf("?")) : urlTemplate;
String existingQuery = hasExistingQuery ?
urlTemplate.substring(urlTemplate.indexOf("?") + 1) : "";
-
- // handle new query parameters
+
+ // 处理新的查询参数
Review Comment:
change Chinese to English pls
##########
shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/request/RequestConfigHelper.java:
##########
@@ -117,25 +97,86 @@ public boolean isArgsToUrlParam() {
*/
public static String buildPath(final String urlTemplate, final JsonObject
argsPosition,
final JsonObject inputJson) {
- // First, check if the input value is already a complete URL
- for (String key : argsPosition.keySet()) {
- if (inputJson.has(key)) {
- String value = inputJson.get(key).getAsString();
- // If the input value is already a complete URL, return it
directly
- if (value.startsWith("http://") ||
value.startsWith("https://")) {
- return value;
- }
- }
+ // 首先检查输入值是否已经是一个完整的 URL
+ if (isCompleteUrl(argsPosition, inputJson)) {
+ return getCompleteUrl(argsPosition, inputJson);
}
-
+
StringBuilder queryBuilder = new StringBuilder();
-
- // Check if the URL template already contains query parameters
+
+ // 检查 URL 模板中是否已经包含查询参数
boolean hasExistingQuery = urlTemplate.contains("?");
String basePath = hasExistingQuery ? urlTemplate.substring(0,
urlTemplate.indexOf("?")) : urlTemplate;
String existingQuery = hasExistingQuery ?
urlTemplate.substring(urlTemplate.indexOf("?") + 1) : "";
-
- // handle new query parameters
+
+ // 处理新的查询参数
+ basePath = processArguments(argsPosition, inputJson, basePath,
queryBuilder);
+
+ // 清理未替换的模板变量
Review Comment:
here too
##########
shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/request/RequestConfigHelper.java:
##########
@@ -161,66 +202,47 @@ public static String buildPath(final String urlTemplate,
final JsonObject argsPo
}
}
}
-
- // clean up the base path by removing any placeholders that were not
replaced
- basePath = basePath.replaceAll("\\{\\{\\.[^}]+}}", "");
-
- // build the final path
+ return modifiedBasePath;
+ }
+
+ /**
+ * Build the final path with query parameters.
+ *
+ * @param basePath the base path
+ * @param queryBuilder the query builder
+ * @param hasExistingQuery whether there are existing query parameters
+ * @param existingQuery the existing query string
+ * @return the final path
+ */
+ private static String buildFinalPath(final String basePath, final
StringBuilder queryBuilder,
+ final boolean hasExistingQuery, final
String existingQuery) {
StringBuilder finalPath = new StringBuilder(basePath);
-
- // add new query parameters if any
+
+ // 添加查询参数
Review Comment:
and here
##########
shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/request/RequestConfigHelper.java:
##########
@@ -145,10 +186,10 @@ public static String buildPath(final String urlTemplate,
final JsonObject argsPo
value = value.substring(0, value.indexOf("?"));
}
value = value.replace("\"", "").trim();
- basePath = basePath.replace("{{." + key + "}}", value);
+ modifiedBasePath = modifiedBasePath.replace("{{." + key +
"}}", value);
} else if ("query".equals(position) && inputJson.has(key)) {
- // handle query parameters
- if (!existingQuery.contains(key + "=")) {
+ // 处理查询参数
Review Comment:
and here
--
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]