zhangshenghang commented on code in PR #9968:
URL: https://github.com/apache/seatunnel/pull/9968#discussion_r2498987342
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/service/BaseLogService.java:
##########
@@ -47,30 +53,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());
}
Review Comment:
When code != 200, the resource is not released; please release it.
You can refer to:
```java
int code = connection.getResponseCode();
if (code == 200) {
return readAll(connection.getInputStream());
}
try (InputStream errorStream = connection.getErrorStream()) {
if (errorStream != null) {
byte[] buffer = new byte[1024];
while (errorStream.read(buffer) != -1) {
}
}
}
```
--
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]