This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 83ff6389d [ISSUE #3011] Method manually handles closing an
auto-closeable resource [TCPClientHandler]
83ff6389d is described below
commit 83ff6389d890d79a9f6c164e540b94fb041ac78a
Author: maheshnikam <[email protected]>
AuthorDate: Mon May 15 17:47:09 2023 +0530
[ISSUE #3011] Method manually handles closing an auto-closeable resource
[TCPClientHandler]
---
.../runtime/admin/handler/TCPClientHandler.java | 33 ++++++----------------
1 file changed, 8 insertions(+), 25 deletions(-)
diff --git
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java
index 28fcca9e0..0eb2b13ef 100644
---
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java
+++
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java
@@ -80,8 +80,8 @@ public class TCPClientHandler extends AbstractHttpHandler {
* DELETE /client/tcp
*/
void delete(HttpExchange httpExchange) throws IOException {
- OutputStream out = httpExchange.getResponseBody();
- try {
+
+ try (OutputStream out = httpExchange.getResponseBody()) {
String request =
HttpExchangeUtils.streamToString(httpExchange.getRequestBody());
DeleteTCPClientRequest deleteTCPClientRequest =
JsonUtils.parseObject(request, DeleteTCPClientRequest.class);
String host = deleteTCPClientRequest.getHost();
@@ -113,15 +113,7 @@ public class TCPClientHandler extends AbstractHttpHandler {
Error error = new Error(e.toString(), stackTrace);
String result = JsonUtils.toJSONString(error);
httpExchange.sendResponseHeaders(500,
result.getBytes(Constants.DEFAULT_CHARSET).length);
- out.write(result.getBytes(Constants.DEFAULT_CHARSET));
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- log.warn("out close failed...", e);
- }
- }
+ log.error(result, e);
}
}
@@ -129,11 +121,10 @@ public class TCPClientHandler extends AbstractHttpHandler
{
* GET /client/tcp Return a response that contains the list of clients
*/
void list(HttpExchange httpExchange) throws IOException {
- OutputStream out = httpExchange.getResponseBody();
- httpExchange.getResponseHeaders().add("Content-Type",
"application/json");
- httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin",
"*");
- try {
+ try (OutputStream out = httpExchange.getResponseBody()) {
+ httpExchange.getResponseHeaders().add("Content-Type",
"application/json");
+
httpExchange.getResponseHeaders().add("Access-Control-Allow-Origin", "*");
// Get the list of TCP clients
ClientSessionGroupMapping clientSessionGroupMapping =
eventMeshTCPServer.getClientSessionGroupMapping();
Map<InetSocketAddress, Session> sessionMap =
clientSessionGroupMapping.getSessionMap();
@@ -176,16 +167,8 @@ public class TCPClientHandler extends AbstractHttpHandler {
Error error = new Error(e.toString(), stackTrace);
String result = JsonUtils.toJSONString(error);
httpExchange.sendResponseHeaders(500,
result.getBytes(Constants.DEFAULT_CHARSET).length);
- out.write(result.getBytes(Constants.DEFAULT_CHARSET));
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- log.warn("out close failed...", e);
- }
- }
- }
+ log.error(result, e);
+ }
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]