jihoonson commented on a change in pull request #9938:
URL: https://github.com/apache/druid/pull/9938#discussion_r500506192



##########
File path: 
extensions-contrib/influxdb-emitter/src/main/java/org/apache/druid/emitter/influxdb/InfluxdbEmitter.java
##########
@@ -211,4 +219,46 @@ public void 
transformAndSendToInfluxdb(LinkedBlockingQueue<ServiceMetricEvent> e
     postToInflux(payload.toString());
   }
 
+  private HttpClient buildInfluxdbClient()
+  {
+    if ("https".equals(influxdbEmitterConfig.getProtocol())) {
+      SSLContext sslContext;
+      if (influxdbEmitterConfig.getTrustStorePath() == null || 
influxdbEmitterConfig.getTrustStorePassword() == null) {
+        String msg = "Can't load TrustStore. Truststore path or password is 
not set.";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+
+      FileInputStream in = null;
+
+      try {
+        in = new FileInputStream(new 
File(influxdbEmitterConfig.getTrustStorePath()));
+        KeyStore store = 
KeyStore.getInstance(influxdbEmitterConfig.getTrustStoreType());
+        store.load(in, 
influxdbEmitterConfig.getTrustStorePassword().toCharArray());
+        TrustManagerFactory tmf = 
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+        tmf.init(store);
+        sslContext = SSLContext.getInstance("TLS");
+        sslContext.init(null, tmf.getTrustManagers(), null);
+      }
+      catch (Exception ex) {
+        String msg = "Unable to load TrustStore";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+      finally {
+        if (in != null) {
+          try {
+            in.close();
+          }
+          catch (IOException ex) {
+            log.error("Unable to load TrustStore");

Review comment:
       I think this should be thrown.

##########
File path: 
extensions-contrib/influxdb-emitter/src/main/java/org/apache/druid/emitter/influxdb/InfluxdbEmitter.java
##########
@@ -211,4 +219,46 @@ public void 
transformAndSendToInfluxdb(LinkedBlockingQueue<ServiceMetricEvent> e
     postToInflux(payload.toString());
   }
 
+  private HttpClient buildInfluxdbClient()
+  {
+    if ("https".equals(influxdbEmitterConfig.getProtocol())) {
+      SSLContext sslContext;
+      if (influxdbEmitterConfig.getTrustStorePath() == null || 
influxdbEmitterConfig.getTrustStorePassword() == null) {
+        String msg = "Can't load TrustStore. Truststore path or password is 
not set.";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+
+      FileInputStream in = null;
+
+      try {
+        in = new FileInputStream(new 
File(influxdbEmitterConfig.getTrustStorePath()));
+        KeyStore store = 
KeyStore.getInstance(influxdbEmitterConfig.getTrustStoreType());
+        store.load(in, 
influxdbEmitterConfig.getTrustStorePassword().toCharArray());
+        TrustManagerFactory tmf = 
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+        tmf.init(store);
+        sslContext = SSLContext.getInstance("TLS");
+        sslContext.init(null, tmf.getTrustManagers(), null);
+      }
+      catch (Exception ex) {
+        String msg = "Unable to load TrustStore";
+        log.error(msg);
+        throw new IllegalStateException(msg);
+      }
+      finally {
+        if (in != null) {

Review comment:
       It would be better to use `try-with-resources`. You will not have to 
handle the IOException thrown in `close()` by yourself.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to