Update for SNI checking
[policy/models.git] / models-sim / policy-models-simulators / src / main / java / org / onap / policy / models / simulators / Main.java
index f82423c..e14beab 100644 (file)
@@ -1,7 +1,8 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * Modifications Copyright 2023 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,6 +32,7 @@ import java.util.Properties;
 import java.util.concurrent.atomic.AtomicReference;
 import lombok.AccessLevel;
 import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
 import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.event.comm.TopicSink;
 import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -45,6 +47,7 @@ import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.common.utils.services.ServiceManagerContainer;
 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
 import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
@@ -104,6 +107,12 @@ public class Main extends ServiceManagerContainer {
         // @formatter:off
         for (ClassRestServerParameters restsim : params.getRestServers()) {
             AtomicReference<HttpServletServer> ref = new AtomicReference<>();
+            if (StringUtils.isNotBlank(restsim.getResourceLocation())) {
+                String resourceLocationId = restsim.getProviderClass() + "_RESOURCE_LOCATION";
+                addAction(resourceLocationId,
+                    () -> Registry.register(resourceLocationId, restsim.getResourceLocation()),
+                    () -> Registry.unregister(resourceLocationId));
+            }
             addAction(restsim.getName(),
                 () -> ref.set(buildRestServer(dmaapName, restsim)),
                 () -> ref.get().shutdown());
@@ -165,7 +174,7 @@ public class Main extends ServiceManagerContainer {
 
     private SimulatorParameters readParameters(String paramFile) {
         try {
-            String paramsJson = getResourceAsString(paramFile);
+            var paramsJson = getResourceAsString(paramFile);
             if (paramsJson == null) {
                 throw new IllegalArgumentException(new FileNotFoundException(paramFile));
             }
@@ -183,14 +192,14 @@ public class Main extends ServiceManagerContainer {
     }
 
     private DmaapSimProvider buildDmaapProvider(DmaapSimParameterGroup params) {
-        DmaapSimProvider prov = new DmaapSimProvider(params);
+        var prov = new DmaapSimProvider(params);
         DmaapSimProvider.setInstance(prov);
         prov.start();
         return prov;
     }
 
     private CdsSimulator buildCdsSimulator(CdsServerParameters params) throws IOException {
-        CdsSimulator cdsSimulator = new CdsSimulator(params.getHost(), params.getPort(), params.getResourceLocation(),
+        var cdsSimulator = new CdsSimulator(params.getHost(), params.getPort(), params.getResourceLocation(),
             params.getSuccessRepeatCount(), params.getRequestedResponseDelayMs());
         cdsSimulator.start();
         return cdsSimulator;
@@ -211,7 +220,7 @@ public class Main extends ServiceManagerContainer {
 
     private HttpServletServer buildRestServer(String dmaapName, ClassRestServerParameters params) {
         try {
-            Properties props = getServerProperties(dmaapName, params);
+            var props = getServerProperties(dmaapName, params);
             HttpServletServer testServer = makeServer(props);
             testServer.waitedStart(5000);
 
@@ -263,7 +272,7 @@ public class Main extends ServiceManagerContainer {
      * @return a set of properties representing the given parameters
      */
     private static Properties getServerProperties(String dmaapName, ClassRestServerParameters params) {
-        final Properties props = new Properties();
+        final var props = new Properties();
         props.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, params.getName());
 
         final String svcpfx = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + params.getName();
@@ -278,6 +287,7 @@ public class Main extends ServiceManagerContainer {
                         params.getProviderClass());
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "false");
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "false");
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SNI_HOST_CHECK_SUFFIX, "false");
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
 
         if (dmaapName != null && dmaapName.equals(params.getName())) {