From cb9d94639aefe04d6dc54b0dfe50d79cde1e5d21 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 30 Oct 2023 13:00:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20API=E6=95=B0=E6=8D=AE=E6=BA=90API?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/server/DatasourceServer.java | 10 ++-- .../io/dataease/utils/HttpClientUtil.java | 52 +++++++++++-------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index b66e6e2ae8..91a8a00ab3 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -125,10 +125,12 @@ public class DatasourceServer implements DatasourceApi { if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) { DEException.throwException(Translator.get("i18n_pid_not_eq_id")); } - List ids = new ArrayList<>(); - getParents(dataSourceDTO.getPid(), ids); - if (ids.contains(dataSourceDTO.getId())) { - DEException.throwException(Translator.get("i18n_pid_not_eq_id")); + if (dataSourceDTO.getPid() != 0) { + List ids = new ArrayList<>(); + getParents(dataSourceDTO.getPid(), ids); + if (ids.contains(dataSourceDTO.getId())) { + DEException.throwException(Translator.get("i18n_pid_not_eq_id")); + } } dataSourceManage.move(dataSourceDTO); } diff --git a/sdk/common/src/main/java/io/dataease/utils/HttpClientUtil.java b/sdk/common/src/main/java/io/dataease/utils/HttpClientUtil.java index 9cb38b703a..ee0f649c01 100755 --- a/sdk/common/src/main/java/io/dataease/utils/HttpClientUtil.java +++ b/sdk/common/src/main/java/io/dataease/utils/HttpClientUtil.java @@ -78,13 +78,14 @@ public class HttpClientUtil { * @return 响应结果字符串 */ public static String get(String url, HttpClientConfig config) { - CloseableHttpClient httpClient = buildHttpClient(url); - HttpGet httpGet = new HttpGet(url); - - if (config == null) { - config = new HttpClientConfig(); - } + CloseableHttpClient httpClient = null; try { + httpClient = buildHttpClient(url); + HttpGet httpGet = new HttpGet(url); + + if (config == null) { + config = new HttpClientConfig(); + } httpGet.setConfig(config.buildRequestConfig()); Map header = config.getHeader(); @@ -98,7 +99,9 @@ public class HttpClientUtil { throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); } finally { try { - httpClient.close(); + if(httpClient != null){ + httpClient.close(); + } } catch (Exception e) { logger.error("HttpClient关闭连接失败", e); } @@ -143,14 +146,14 @@ public class HttpClientUtil { * @return 响应结果字符串 */ public static String post(String url, String json, HttpClientConfig config) { - CloseableHttpClient httpClient = buildHttpClient(url); - HttpPost httpPost = new HttpPost(url); - if (config == null) { - config = new HttpClientConfig(); - } + CloseableHttpClient httpClient = null; try { + buildHttpClient(url); + HttpPost httpPost = new HttpPost(url); + if (config == null) { + config = new HttpClientConfig(); + } httpPost.setConfig(config.buildRequestConfig()); - Map header = config.getHeader(); for (String key : header.keySet()) { httpPost.addHeader(key, header.get(key)); @@ -168,7 +171,9 @@ public class HttpClientUtil { throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); } finally { try { - httpClient.close(); + if(httpClient != null){ + httpClient.close(); + } } catch (Exception e) { logger.error("HttpClient关闭连接失败", e); } @@ -195,14 +200,15 @@ public class HttpClientUtil { * @return 响应结果字符串 */ public static String post(String url, Map body, HttpClientConfig config) { - CloseableHttpClient httpClient = buildHttpClient(url); - HttpPost httpPost = new HttpPost(url); - if (config == null) { - config = new HttpClientConfig(); - } - try { - httpPost.setConfig(config.buildRequestConfig()); + CloseableHttpClient httpClient = null; + try { + buildHttpClient(url); + HttpPost httpPost = new HttpPost(url); + if (config == null) { + config = new HttpClientConfig(); + } + httpPost.setConfig(config.buildRequestConfig()); Map header = config.getHeader(); for (String key : header.keySet()) { httpPost.addHeader(key, header.get(key)); @@ -227,7 +233,9 @@ public class HttpClientUtil { throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); } finally { try { - httpClient.close(); + if(httpClient != null){ + httpClient.close(); + } } catch (Exception e) { logger.error("HttpClient关闭连接失败", e); }