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

benjobs pushed a commit to branch check_http
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git

commit 209c85d6d1dcdb922125752cfec304834622a9a9
Author: benjobs <[email protected]>
AuthorDate: Mon Dec 11 00:05:33 2023 +0800

    [Improve] http check improvement
---
 .../main/scala/org/apache/streampark/common/util/Utils.scala  | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
 
b/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
index 5ab002ab2..e5bc05121 100644
--- 
a/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
+++ 
b/streampark-common/src/main/scala/org/apache/streampark/common/util/Utils.scala
@@ -19,7 +19,7 @@ package org.apache.streampark.common.util
 import org.apache.commons.lang3.StringUtils
 
 import java.io._
-import java.net.URL
+import java.net.{HttpURLConnection, URL}
 import java.time.{Duration, LocalDateTime}
 import java.util.{jar, Collection => JavaCollection, Map => JavaMap, 
Properties, UUID}
 import java.util.concurrent.locks.LockSupport
@@ -156,6 +156,15 @@ object Utils extends Logger {
     }
   }
 
+  def checkHttpURL(urlString: String) = {
+    Try {
+      val url = new URL(urlString)
+      val connection = url.openConnection.asInstanceOf[HttpURLConnection]
+      connection.setRequestMethod("HEAD")
+      connection.getResponseCode == HttpURLConnection.HTTP_OK
+    }.getOrElse(false)
+  }
+
   def printLogo(info: String): Unit = {
     // scalastyle:off println
     println("\n")

Reply via email to