wuxiansen commented on code in PR #9968:
URL: https://github.com/apache/seatunnel/pull/9968#discussion_r2496865752


##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseLogService.java:
##########
@@ -47,30 +47,87 @@ public String getLogPath() {
     }
 
     protected String sendGet(String urlString) {
+        HttpURLConnection connection = null;
         try {
-            HttpURLConnection connection = (HttpURLConnection) new 
URL(urlString).openConnection();
+            connection = (HttpURLConnection) new 
URL(urlString).openConnection();
             connection.setRequestMethod("GET");
             connection.setConnectTimeout(5000);
             connection.setReadTimeout(5000);
             connection.connect();
 
+            int code = connection.getResponseCode();
             if (connection.getResponseCode() == 200) {
-                try (InputStream is = connection.getInputStream();
-                        ByteArrayOutputStream baos = new 
ByteArrayOutputStream()) {
-                    byte[] buffer = new byte[1024];
-                    int len;
-                    while ((len = is.read(buffer)) != -1) {
-                        baos.write(buffer, 0, len);
-                    }
-                    return baos.toString();
-                }
+                return readAll(connection.getInputStream());
             }
+            log.warn("GET {} -> HTTP {}", urlString, code);
         } catch (IOException e) {
-            log.error("Send get Fail.{}", ExceptionUtils.getMessage(e));
+            log.error("Send GET failed: url={}, err={}", urlString, 
ExceptionUtils.getMessage(e));
+        } finally {
+            if (connection != null) {
+                connection.disconnect();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Send GET request with Basic Auth
+     *
+     * @param urlString url
+     * @param user name
+     * @param pass password
+     * @return log
+     */
+    protected String sendGet(String urlString, String user, String pass) {
+        HttpURLConnection connection = null;
+        try {
+            connection = (HttpURLConnection) new 
URL(urlString).openConnection();
+            connection.setRequestMethod("GET");
+            connection.setConnectTimeout(5000);
+            connection.setReadTimeout(5000);
+
+            // Basic Auth
+            if (user != null && pass != null) {
+                String token =
+                        java.util.Base64.getEncoder()
+                                .encodeToString(
+                                        (user + ":" + pass)
+                                                
.getBytes(java.nio.charset.StandardCharsets.UTF_8));
+                connection.setRequestProperty("Authorization", "Basic " + 
token);

Review Comment:
   This is private and can be referenced,`HttpHeaders.Authorization` .



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseLogService.java:
##########
@@ -47,30 +47,87 @@ public String getLogPath() {
     }
 
     protected String sendGet(String urlString) {
+        HttpURLConnection connection = null;
         try {
-            HttpURLConnection connection = (HttpURLConnection) new 
URL(urlString).openConnection();
+            connection = (HttpURLConnection) new 
URL(urlString).openConnection();
             connection.setRequestMethod("GET");
             connection.setConnectTimeout(5000);
             connection.setReadTimeout(5000);
             connection.connect();
 
+            int code = connection.getResponseCode();
             if (connection.getResponseCode() == 200) {
-                try (InputStream is = connection.getInputStream();
-                        ByteArrayOutputStream baos = new 
ByteArrayOutputStream()) {
-                    byte[] buffer = new byte[1024];
-                    int len;
-                    while ((len = is.read(buffer)) != -1) {
-                        baos.write(buffer, 0, len);
-                    }
-                    return baos.toString();
-                }
+                return readAll(connection.getInputStream());
             }
+            log.warn("GET {} -> HTTP {}", urlString, code);
         } catch (IOException e) {
-            log.error("Send get Fail.{}", ExceptionUtils.getMessage(e));
+            log.error("Send GET failed: url={}, err={}", urlString, 
ExceptionUtils.getMessage(e));
+        } finally {
+            if (connection != null) {
+                connection.disconnect();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Send GET request with Basic Auth
+     *
+     * @param urlString url
+     * @param user name
+     * @param pass password
+     * @return log
+     */
+    protected String sendGet(String urlString, String user, String pass) {
+        HttpURLConnection connection = null;
+        try {
+            connection = (HttpURLConnection) new 
URL(urlString).openConnection();
+            connection.setRequestMethod("GET");
+            connection.setConnectTimeout(5000);
+            connection.setReadTimeout(5000);
+
+            // Basic Auth
+            if (user != null && pass != null) {
+                String token =
+                        java.util.Base64.getEncoder()
+                                .encodeToString(
+                                        (user + ":" + pass)
+                                                
.getBytes(java.nio.charset.StandardCharsets.UTF_8));
+                connection.setRequestProperty("Authorization", "Basic " + 
token);

Review Comment:
   This is private and can be referenced,`HttpHeaders.Authorization` .



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to