You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by ch...@apache.org on 2022/10/24 07:23:56 UTC

[incubator-eventmesh] branch master updated: [ISSUE #1692] Method may fail to close stream

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

chenguangsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new f8e84631 [ISSUE #1692] Method may fail to close stream
     new d1c725ef Merge pull request #1802 from shinnlok/patch-1
f8e84631 is described below

commit f8e84631769be7d4f5caf26a89d83a9e071f10d7
Author: Shinn Lok <sh...@gmail.com>
AuthorDate: Sun Oct 23 23:13:17 2022 -0700

    [ISSUE #1692] Method may fail to close stream
---
 .../apache/eventmesh/runtime/boot/SSLContextFactory.java    | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java
index 80659ac2..446155a1 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java
@@ -25,6 +25,7 @@ import org.apache.eventmesh.runtime.constants.EventMeshConstants;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.File;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
@@ -48,6 +49,7 @@ public class SSLContextFactory {
 
     public static SSLContext getSslContext(EventMeshHTTPConfiguration eventMeshHttpConfiguration) {
         SSLContext sslContext;
+        InputStream inputStream;
         try {
             protocol = eventMeshHttpConfiguration.eventMeshServerSSLProtocol;
 
@@ -60,15 +62,20 @@ public class SSLContextFactory {
             }
             sslContext = SSLContext.getInstance(protocol);
             KeyStore keyStore = KeyStore.getInstance("JKS");
-            keyStore.load(Files.newInputStream(Paths.get(EventMeshConstants.EVENTMESH_CONF_HOME
-                    + File.separator
-                    + fileName), StandardOpenOption.READ), filePass);
+            inputStream = Files.newInputStream(Paths.get(EventMeshConstants.EVENTMESH_CONF_HOME
+                                              + File.separator
+                                              + fileName), StandardOpenOption.READ)
+            keyStore.load(inputStream, filePass);
             KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
             kmf.init(keyStore, filePass);
             sslContext.init(kmf.getKeyManagers(), null, null);
         } catch (Exception e) {
             httpLogger.warn("sslContext init failed", e);
             sslContext = null;
+        } finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
         }
         return sslContext;
     }


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