This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 40eb2f832 [INLONG-5197][Manager] Unify the HTTP request method of the 
OpenAPI query interface from GET to POST (#5198)
40eb2f832 is described below

commit 40eb2f832bb06fc8ec02a1da58d1b7cbe862f79b
Author: woofyzhao <[email protected]>
AuthorDate: Tue Jul 26 17:31:41 2022 +0800

    [INLONG-5197][Manager] Unify the HTTP request method of the OpenAPI query 
interface from GET to POST (#5198)
---
 .../pojo/dataproxy/DataProxyConfigRequest.java     | 45 ++++++++++++++++++++++
 .../inlong/dataproxy/config/ConfigManager.java     | 29 ++++++++------
 .../dataproxy/config/RemoteConfigManager.java      | 35 ++++++++++-------
 .../apache/inlong/dataproxy/utils/HttpUtils.java   | 37 ++++++++++++++++++
 .../controller/openapi/DataProxyController.java    | 32 ++++++---------
 5 files changed, 133 insertions(+), 45 deletions(-)

diff --git 
a/inlong-common/src/main/java/org/apache/inlong/common/pojo/dataproxy/DataProxyConfigRequest.java
 
b/inlong-common/src/main/java/org/apache/inlong/common/pojo/dataproxy/DataProxyConfigRequest.java
new file mode 100644
index 000000000..c26f3454c
--- /dev/null
+++ 
b/inlong-common/src/main/java/org/apache/inlong/common/pojo/dataproxy/DataProxyConfigRequest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.common.pojo.dataproxy;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Data proxy config request info.
+ */
+@Data
+@NoArgsConstructor
+public class DataProxyConfigRequest {
+
+    /**
+     * DataProxy cluster name
+     */
+    private String clusterName;
+
+    /**
+     * DataProxy cluster tag
+     */
+    private String clusterTag;
+
+    /**
+     * DataProxy cluster md5
+     */
+    private String md5;
+
+}
diff --git 
a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/ConfigManager.java
 
b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/ConfigManager.java
index db1bdb12f..2ba3bb04c 100644
--- 
a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/ConfigManager.java
+++ 
b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/ConfigManager.java
@@ -23,10 +23,11 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpHeaders;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
+import org.apache.inlong.common.pojo.dataproxy.DataProxyConfigRequest;
 import org.apache.inlong.common.pojo.dataproxy.DataProxyTopicInfo;
 import org.apache.inlong.common.pojo.dataproxy.MQClusterInfo;
 import org.apache.inlong.dataproxy.config.holder.FileConfigHolder;
@@ -37,6 +38,7 @@ import 
org.apache.inlong.dataproxy.config.holder.PropertiesConfigHolder;
 import org.apache.inlong.dataproxy.config.pojo.MQClusterConfig;
 import org.apache.inlong.dataproxy.consts.AttributeConstants;
 import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.utils.HttpUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -269,18 +271,23 @@ public class ConfigManager {
                 return false;
             }
 
-            HttpGet httpGet = null;
+            HttpPost httpPost = null;
             try {
-                String url = "http://"; + host + ConfigConstants.MANAGER_PATH + 
ConfigConstants.MANAGER_GET_CONFIG_PATH
-                        + "?clusterName=" + clusterName;
-                LOG.info("start to request {} to get config info", url);
-                httpGet = new HttpGet(url);
-                httpGet.addHeader(HttpHeaders.CONNECTION, "close");
-                httpGet.addHeader(HttpHeaders.AUTHORIZATION, 
AuthUtils.genBasicAuth());
+                String url = "http://"; + host + ConfigConstants.MANAGER_PATH + 
ConfigConstants.MANAGER_GET_CONFIG_PATH;
+                httpPost = new HttpPost(url);
+                httpPost.addHeader(HttpHeaders.CONNECTION, "close");
+                httpPost.addHeader(HttpHeaders.AUTHORIZATION, 
AuthUtils.genBasicAuth());
+
+                // request body
+                DataProxyConfigRequest request = new DataProxyConfigRequest();
+                request.setClusterName(clusterName);
+                httpPost.setEntity(HttpUtils.getEntity(request));
 
                 // request with post
-                CloseableHttpResponse response = httpClient.execute(httpGet);
+                LOG.info("start to request {} to get config info with params 
{}", url, request);
+                CloseableHttpResponse response = httpClient.execute(httpPost);
                 String returnStr = EntityUtils.toString(response.getEntity());
+
                 // get groupId <-> topic and m value.
                 RemoteConfigJson configJson = gson.fromJson(returnStr, 
RemoteConfigJson.class);
                 Map<String, String> groupIdToTopic = new HashMap<>();
@@ -335,8 +342,8 @@ public class ConfigManager {
                 LOG.error("exception caught", ex);
                 return false;
             } finally {
-                if (httpGet != null) {
-                    httpGet.releaseConnection();
+                if (httpPost != null) {
+                    httpPost.releaseConnection();
                 }
             }
             return true;
diff --git 
a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/RemoteConfigManager.java
 
b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/RemoteConfigManager.java
index df5ed5f8c..f2f33ce85 100644
--- 
a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/RemoteConfigManager.java
+++ 
b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/config/RemoteConfigManager.java
@@ -23,7 +23,7 @@ import org.apache.commons.lang3.math.NumberUtils;
 import org.apache.http.HttpHeaders;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.util.EntityUtils;
@@ -31,6 +31,7 @@ import 
org.apache.inlong.common.pojo.dataproxy.CacheClusterObject;
 import org.apache.inlong.common.pojo.dataproxy.CacheClusterSetObject;
 import org.apache.inlong.common.pojo.dataproxy.CacheTopicObject;
 import org.apache.inlong.common.pojo.dataproxy.DataProxyCluster;
+import org.apache.inlong.common.pojo.dataproxy.DataProxyConfigRequest;
 import org.apache.inlong.common.pojo.dataproxy.DataProxyConfigResponse;
 import org.apache.inlong.common.pojo.dataproxy.IRepository;
 import org.apache.inlong.common.pojo.dataproxy.InLongIdObject;
@@ -41,6 +42,7 @@ import org.apache.inlong.common.pojo.dataproxy.ProxySource;
 import org.apache.inlong.common.pojo.dataproxy.RepositoryTimerTask;
 import org.apache.inlong.dataproxy.config.holder.CommonPropertiesHolder;
 import org.apache.inlong.dataproxy.consts.ConfigConstants;
+import org.apache.inlong.dataproxy.utils.HttpUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -182,20 +184,25 @@ public class RemoteConfigManager implements IRepository {
      * reloadDataProxyConfig
      */
     private boolean reloadDataProxyConfig(String clusterName, String 
clusterTag, String host) {
-        HttpGet httpGet = null;
+        HttpPost httpPost = null;
         try {
-            String url = "http://"; + host + ConfigConstants.MANAGER_PATH + 
ConfigConstants.MANAGER_GET_ALL_CONFIG_PATH
-                    + "?clusterName=" + clusterName + "&clusterTag=" + 
clusterTag;
-            if (StringUtils.isNotBlank(this.dataProxyConfigMd5)) {
-                url += "&md5=" + this.dataProxyConfigMd5;
+            String url = "http://"; + host + ConfigConstants.MANAGER_PATH + 
ConfigConstants.MANAGER_GET_ALL_CONFIG_PATH;
+            httpPost = new HttpPost(url);
+            httpPost.addHeader(HttpHeaders.CONNECTION, "close");
+            httpPost.addHeader(HttpHeaders.AUTHORIZATION, 
AuthUtils.genBasicAuth());
+
+            // request body
+            DataProxyConfigRequest request = new DataProxyConfigRequest();
+            request.setClusterName(clusterName);
+            request.setClusterTag(clusterTag);
+            if (StringUtils.isNotBlank(dataProxyConfigMd5)) {
+                request.setMd5(dataProxyConfigMd5);
             }
-            LOGGER.info("start to request {} to get config info", url);
-            httpGet = new HttpGet(url);
-            httpGet.addHeader(HttpHeaders.CONNECTION, "close");
-            httpGet.addHeader(HttpHeaders.AUTHORIZATION, 
AuthUtils.genBasicAuth());
+            httpPost.setEntity(HttpUtils.getEntity(request));
 
-            // request with get
-            CloseableHttpResponse response = httpClient.execute(httpGet);
+            // request with post
+            LOGGER.info("start to request {} to get config info with params 
{}", url, request);
+            CloseableHttpResponse response = httpClient.execute(httpPost);
             String returnStr = EntityUtils.toString(response.getEntity());
             LOGGER.info("end to request {} to get config info:{}", url, 
returnStr);
             // get groupId <-> topic and m value.
@@ -221,8 +228,8 @@ public class RemoteConfigManager implements IRepository {
             LOGGER.error("exception caught", ex);
             return false;
         } finally {
-            if (httpGet != null) {
-                httpGet.releaseConnection();
+            if (httpPost != null) {
+                httpPost.releaseConnection();
             }
         }
         return true;
diff --git 
a/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/HttpUtils.java
 
b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/HttpUtils.java
new file mode 100644
index 000000000..71bba234f
--- /dev/null
+++ 
b/inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/utils/HttpUtils.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.dataproxy.utils;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.http.entity.StringEntity;
+
+import java.io.UnsupportedEncodingException;
+
+public class HttpUtils {
+
+    public static final String APPLICATION_JSON = "application/json";
+    private static final Gson GSON = new GsonBuilder().create();
+
+    public static StringEntity getEntity(Object obj) throws 
UnsupportedEncodingException {
+        StringEntity se = new StringEntity(GSON.toJson(obj));
+        se.setContentType(APPLICATION_JSON);
+        return se;
+    }
+
+}
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/DataProxyController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/DataProxyController.java
index 98f77f6dd..2051a8e8f 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/DataProxyController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/DataProxyController.java
@@ -18,19 +18,20 @@
 package org.apache.inlong.manager.web.controller.openapi;
 
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.inlong.common.pojo.dataproxy.DataProxyConfig;
+import org.apache.inlong.common.pojo.dataproxy.DataProxyConfigRequest;
 import org.apache.inlong.common.pojo.dataproxy.DataProxyNodeResponse;
 import org.apache.inlong.manager.common.beans.Response;
 import org.apache.inlong.manager.service.cluster.InlongClusterService;
 import org.apache.inlong.manager.service.repository.DataProxyConfigRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -42,6 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("/openapi")
 @Api(tags = "Open-DataProxy-API")
+@Slf4j
 public class DataProxyController {
 
     @Autowired
@@ -50,36 +52,26 @@ public class DataProxyController {
     @Autowired
     private DataProxyConfigRepository dataProxyConfigRepository;
 
-    @GetMapping(value = "/dataproxy/getIpList/{inlongGroupId}")
+    @PostMapping(value = "/dataproxy/getIpList/{inlongGroupId}")
     @ApiOperation(value = "Get data proxy IP list by InlongGroupId")
     public Response<DataProxyNodeResponse> getIpList(@PathVariable String 
inlongGroupId) {
         return 
Response.success(clusterService.getDataProxyNodes(inlongGroupId));
     }
 
-    @GetMapping("/dataproxy/getConfig")
+    @PostMapping("/dataproxy/getConfig")
     @ApiOperation(value = "Get data proxy topic list")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "clusterTag", value = "cluster tag", 
dataTypeClass = String.class),
-            @ApiImplicitParam(name = "clusterName", value = "cluster name", 
dataTypeClass = String.class)
-    })
-    public Response<DataProxyConfig> getConfig(
-            @RequestParam(required = false) String clusterTag,
-            @RequestParam(required = true) String clusterName) {
-        DataProxyConfig config = clusterService.getDataProxyConfig(clusterTag, 
clusterName);
+    public Response<DataProxyConfig> getConfig(@RequestBody 
DataProxyConfigRequest request) {
+        DataProxyConfig config = 
clusterService.getDataProxyConfig(request.getClusterTag(), 
request.getClusterName());
         if (CollectionUtils.isEmpty(config.getMqClusterList()) || 
CollectionUtils.isEmpty(config.getTopicList())) {
             return Response.fail("Failed to get MQ Cluster or Topic, make sure 
Cluster registered or Topic existed.");
         }
         return Response.success(config);
     }
 
-    @GetMapping("/dataproxy/getAllConfig")
+    @PostMapping("/dataproxy/getAllConfig")
     @ApiOperation(value = "Get all proxy config")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "clusterName", dataTypeClass = 
String.class, required = true),
-            @ApiImplicitParam(name = "md5", dataTypeClass = String.class, 
required = true)
-    })
-    public String getAllConfig(@RequestParam String clusterName, 
@RequestParam(required = false) String md5) {
-        return clusterService.getAllConfig(clusterName, md5);
+    public String getAllConfig(@RequestBody DataProxyConfigRequest request) {
+        return clusterService.getAllConfig(request.getClusterName(), 
request.getMd5());
     }
 
     @RequestMapping(value = "/changeClusterTag", method = RequestMethod.PUT)

Reply via email to