diff --git a/de-xpack b/de-xpack index 47251c7975..22554aaec0 160000 --- a/de-xpack +++ b/de-xpack @@ -1 +1 @@ -Subproject commit 47251c7975cbee373fd183a3426b3b24526d1d65 +Subproject commit 22554aaec016346ee0605f8e8923b1a858e1f1b7 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 a8ef27cc28..79f799aed3 100755 --- a/sdk/common/src/main/java/io/dataease/utils/HttpClientUtil.java +++ b/sdk/common/src/main/java/io/dataease/utils/HttpClientUtil.java @@ -31,7 +31,10 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.security.cert.X509Certificate; import java.util.*; @@ -521,4 +524,28 @@ public class HttpClientUtil { } } } + + public static boolean isURLReachable(String urlString, Map head) { + try { + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setConnectTimeout(5000); // 设置连接超时时间,单位为毫秒 + connection.setReadTimeout(5000); // 设置读取超时时间,单位为毫秒 + if (MapUtils.isNotEmpty(head)) { + for (Map.Entry entry : head.entrySet()) { + connection.addRequestProperty(entry.getKey(), entry.getValue()); + } + } + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + return true; // 状态码200表示URL可达 + } else if (StringUtils.equalsIgnoreCase("Unauthorized", connection.getResponseMessage())) { + LogUtil.error("apisix key error [failed to check token]"); + } + } catch (IOException e) { + return false; + } + return false; // 如果发生异常或状态码不是200,则URL不可达 + } }