Fix sonar issues
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / service / ModelLoaderService.java
index f8ab60f..22f7671 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.aai.modelloader.service;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -30,9 +31,11 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Timer;
 import java.util.TimerTask;
+
 import javax.annotation.PostConstruct;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+
 import org.onap.aai.cl.api.Logger;
 import org.onap.aai.cl.eelf.LoggerFactory;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
@@ -78,9 +81,24 @@ public class ModelLoaderService implements ModelLoaderInterface {
         logger.info(ModelLoaderMsgs.LOADING_CONFIGURATION);
         ModelLoaderConfig.setConfigHome(configDir);
         Properties configProperties = new Properties();
-        try {
-            configProperties.load(Files.newInputStream(Paths.get(configDir, "model-loader.properties")));
+        try (InputStream configInputStream = Files.newInputStream(Paths.get(configDir, "model-loader.properties"))) {
+            configProperties.load(configInputStream);
             config = new ModelLoaderConfig(configProperties);
+            
+            // Set the truststore for SDC Client to connect to Dmaap central bus if applicable (as in case of TI)
+            if (Boolean.TRUE.equals(config.isUseHttpsWithDmaap())) {
+                String trustStorePath = config.getKeyStorePath();
+                String trustStorePassword = config.getKeyStorePassword();
+                if (trustStorePath != null && Paths.get(trustStorePath).toFile().isFile() && trustStorePassword != null
+                        && !trustStorePassword.isEmpty()) {
+                    System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+                    System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+                } else {
+                    throw new IllegalArgumentException("Model Loader property ml.distribution.KEYSTORE_FILE "
+                               + "or ml.distribution.KEYSTORE_PASSWORD not set or invalid");
+                }
+            }
+            
             if (!config.getASDCConnectionDisabled()) {
                 initSdcClient();
             }
@@ -107,7 +125,7 @@ public class ModelLoaderService implements ModelLoaderInterface {
         // Initialize distribution client
         logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client...");
         client = DistributionClientFactory.createDistributionClient();
-        EventCallback callback = new EventCallback(client, config);
+        EventCallback callback = new EventCallback(client, config, babelClientFactory);
 
         IDistributionClientResult initResult = client.init(config, callback);