forked from github/dataease
fix(X-Pack): 社区版本启动有xpack报错信息 #11317
This commit is contained in:
parent
eb9ce597dd
commit
ca66de0b8e
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
||||
Subproject commit 47251c7975cbee373fd183a3426b3b24526d1d65
|
||||
Subproject commit 22554aaec016346ee0605f8e8923b1a858e1f1b7
|
@ -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<String, String> 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<String, String> 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不可达
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user