You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by "PickBas (via GitHub)" <gi...@apache.org> on 2023/05/09 08:18:12 UTC

[GitHub] [eventmesh] PickBas opened a new pull request, #3891: [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler]

PickBas opened a new pull request, #3891:
URL: https://github.com/apache/eventmesh/pull/3891

   Fixes #3010.
   
   ### Modifications
   Used try-with-resources for OutputStream
   
   ### Documentation
   - Does this pull request introduce a new feature? (no)
   


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [eventmesh] PickBas commented on a diff in pull request #3891: [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler]

Posted by "PickBas (via GitHub)" <gi...@apache.org>.
PickBas commented on code in PR #3891:
URL: https://github.com/apache/eventmesh/pull/3891#discussion_r1188807211


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RegistryHandler.java:
##########
@@ -85,33 +84,40 @@ void get(HttpExchange httpExchange) throws IOException {
                 getRegistryResponseList.add(getRegistryResponse);
             }
             getRegistryResponseList.sort(Comparator.comparing(GetRegistryResponse::getEventMeshClusterName));
-
             String result = JsonUtils.toJSONString(getRegistryResponseList);
-            httpExchange.sendResponseHeaders(200, result.getBytes(Constants.DEFAULT_CHARSET).length);
+            httpExchange.sendResponseHeaders(
+                200,
+                Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
+            );
             out.write(result.getBytes(Constants.DEFAULT_CHARSET));
         } catch (NullPointerException e) {
             //registry not initialized, return empty list
             String result = JsonUtils.toJSONString(new ArrayList<>());
-            httpExchange.sendResponseHeaders(200, result.getBytes(Constants.DEFAULT_CHARSET).length);
-            out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+            httpExchange.sendResponseHeaders(
+                200,
+                Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
+            );
+            try (OutputStream out = httpExchange.getResponseBody()) {
+                out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+            } catch (IOException ioe) {
+                log.warn("out close failed...", e);
+            }

Review Comment:
   @mxsm Done! Have a look, please



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler] (eventmesh)

Posted by "harshithasudhakar (via GitHub)" <gi...@apache.org>.
harshithasudhakar commented on PR #3891:
URL: https://github.com/apache/eventmesh/pull/3891#issuecomment-1883418126

   @PickBas Please fix the conflicts


-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


[GitHub] [eventmesh] mxsm commented on a diff in pull request #3891: [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler]

Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on code in PR #3891:
URL: https://github.com/apache/eventmesh/pull/3891#discussion_r1189925010


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RegistryHandler.java:
##########
@@ -85,33 +84,42 @@ void get(HttpExchange httpExchange) throws IOException {
                 getRegistryResponseList.add(getRegistryResponse);
             }
             getRegistryResponseList.sort(Comparator.comparing(GetRegistryResponse::getEventMeshClusterName));
-
             String result = JsonUtils.toJSONString(getRegistryResponseList);
-            httpExchange.sendResponseHeaders(200, result.getBytes(Constants.DEFAULT_CHARSET).length);
+            httpExchange.sendResponseHeaders(
+                200,
+                Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
+            );

Review Comment:
   It needs to be modified here as well.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler] (eventmesh)

Posted by "PickBas (via GitHub)" <gi...@apache.org>.
PickBas closed pull request #3891: [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler] 
URL: https://github.com/apache/eventmesh/pull/3891


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [eventmesh] PickBas commented on a diff in pull request #3891: [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler]

Posted by "PickBas (via GitHub)" <gi...@apache.org>.
PickBas commented on code in PR #3891:
URL: https://github.com/apache/eventmesh/pull/3891#discussion_r1189950202


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RegistryHandler.java:
##########
@@ -85,33 +84,42 @@ void get(HttpExchange httpExchange) throws IOException {
                 getRegistryResponseList.add(getRegistryResponse);
             }
             getRegistryResponseList.sort(Comparator.comparing(GetRegistryResponse::getEventMeshClusterName));
-
             String result = JsonUtils.toJSONString(getRegistryResponseList);
-            httpExchange.sendResponseHeaders(200, result.getBytes(Constants.DEFAULT_CHARSET).length);
+            httpExchange.sendResponseHeaders(
+                200,
+                Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
+            );

Review Comment:
   @mxsm Fixed.



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


[GitHub] [eventmesh] mxsm commented on a diff in pull request #3891: [ISSUE #3010]Method manually handles closing an auto-closeable resource [RegistryHandler]

Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on code in PR #3891:
URL: https://github.com/apache/eventmesh/pull/3891#discussion_r1188794284


##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RegistryHandler.java:
##########
@@ -85,33 +84,40 @@ void get(HttpExchange httpExchange) throws IOException {
                 getRegistryResponseList.add(getRegistryResponse);
             }
             getRegistryResponseList.sort(Comparator.comparing(GetRegistryResponse::getEventMeshClusterName));
-
             String result = JsonUtils.toJSONString(getRegistryResponseList);
-            httpExchange.sendResponseHeaders(200, result.getBytes(Constants.DEFAULT_CHARSET).length);
+            httpExchange.sendResponseHeaders(
+                200,
+                Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
+            );
             out.write(result.getBytes(Constants.DEFAULT_CHARSET));
         } catch (NullPointerException e) {
             //registry not initialized, return empty list
             String result = JsonUtils.toJSONString(new ArrayList<>());
-            httpExchange.sendResponseHeaders(200, result.getBytes(Constants.DEFAULT_CHARSET).length);
-            out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+            httpExchange.sendResponseHeaders(
+                200,
+                Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET).length
+            );
+            try (OutputStream out = httpExchange.getResponseBody()) {
+                out.write(result.getBytes(Constants.DEFAULT_CHARSET));
+            } catch (IOException ioe) {
+                log.warn("out close failed...", e);
+            }

Review Comment:
   how about like this:
   ```
   byte[] bytes = Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET);
   httpExchange.sendResponseHeaders(
                   200,
                   bytes.length
               );
               try (OutputStream out = httpExchange.getResponseBody()) {
                   out.write(bytes);
               } catch (IOException ioe) {
                   log.warn("out close failed...", e);
               }
   ```



-- 
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: issues-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org