bugfix - http/https protocol problem 42/126142/1
authorGuangrong Fu <fu.guangrong@zte.com.cn>
Wed, 8 Dec 2021 08:15:24 +0000 (16:15 +0800)
committerGuangrong Fu <fu.guangrong@zte.com.cn>
Wed, 8 Dec 2021 08:15:29 +0000 (16:15 +0800)
Issue-ID: HOLMES-488

Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Change-Id: I9d4a219b55b909217413dd615013b0d1026e257d

rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTask.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/ConfigFileScanningTaskTest.java

index 88ab637..884ea31 100644 (file)
@@ -22,6 +22,7 @@ import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import org.apache.commons.lang.StringUtils;
 import org.onap.holmes.common.ConfigFileScanner;
+import org.onap.holmes.common.utils.CommonUtils;
 import org.onap.holmes.common.utils.FileUtils;
 import org.onap.holmes.common.utils.JerseyClient;
 import org.onap.holmes.rulemgt.bean.request.RuleCreateRequest;
@@ -43,10 +44,11 @@ public class ConfigFileScanningTask implements Runnable {
     final private Map<String, String> configInEffect = new HashMap(); // Contents for configInEffect are <closedControlLoop>:<ruleContents> pairs.
     private String configFile = "/opt/hrmrules/index.json";
     private ConfigFileScanner configFileScanner;
-    private String url = "https://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
+    private String url;
 
     public ConfigFileScanningTask(ConfigFileScanner configFileScanner) {
         this.configFileScanner = configFileScanner;
+        this.url = getRequestPref() + "://127.0.0.1:9101/api/holmes-rule-mgmt/v1/rule";
     }
 
     @Override
@@ -193,4 +195,8 @@ public class ConfigFileScanningTask implements Runnable {
         }
         return true;
     }
+
+    private String getRequestPref() {
+        return CommonUtils.isHttpsEnabled() ? JerseyClient.PROTOCOL_HTTPS : JerseyClient.PROTOCOL_HTTP;
+    }
 }
index 053612b..d6d93a9 100644 (file)
@@ -44,6 +44,8 @@ public class ConfigFileScanningTaskTest {
 
     @Test
     public void run_add_rules() throws Exception {
+        System.setProperty("ENABLE_ENCRYPT", "true");
+
         String clName = "ControlLoop-VOLTE-2179b738-fd36-4843-a71a-a8c24c70c55b";
         String indexPath = getFilePath("index-add.json");
         String contents = FileUtils.readTextFile(indexPath);
@@ -68,10 +70,14 @@ public class ConfigFileScanningTaskTest {
 
         Map<String, String> config = Whitebox.getInternalState(cfst, "configInEffect");
         assertThat(config.size(), is(1));
+
+        System.clearProperty("ENABLE_ENCRYPT");
     }
 
     @Test
     public void run_remove_rules_normal() throws Exception {
+        System.setProperty("ENABLE_ENCRYPT", "false");
+
         String clName = "ControlLoop-VOLTE-2179b738-fd36-4843-a71a-a8c24c70c55b";
         String indexPath = getFilePath("index-add.json");
         String contents = FileUtils.readTextFile(indexPath);
@@ -98,6 +104,8 @@ public class ConfigFileScanningTaskTest {
 
         Map<String, String> config = Whitebox.getInternalState(cfst, "configInEffect");
         assertThat(config.size(), is(0));
+
+        System.clearProperty("ENABLE_ENCRYPT");
     }
 
     @Test
@@ -238,4 +246,6 @@ public class ConfigFileScanningTaskTest {
         ruleResult4API.setEnabled(1);
         return ruleResult4API;
     }
+
+
 }
\ No newline at end of file