Fix handling of non-OSGi 76/114776/1
authorDan Timoney <dtimoney@att.com>
Tue, 10 Nov 2020 17:54:21 +0000 (12:54 -0500)
committerDan Timoney <dtimoney@att.com>
Tue, 10 Nov 2020 17:54:21 +0000 (12:54 -0500)
Fixed handling of case where aai-service and netbox-client are
called outside OSGi container.

Change-Id: Ie83dd217a77a021a30d171e0964d9ac709e40cc8
Issue-ID: CCSDK-2976
Signed-off-by: Dan Timoney <dtimoney@att.com>
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIRequest.java
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceProvider.java
netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java

index 0515218..9facab8 100755 (executable)
@@ -162,8 +162,11 @@ public abstract class AAIRequest {
         AAIRequest.configProperties = props;
         AAIRequest.aaiService = aaiService;
 
+        InputStream in = null;
+
         try
         {
+            LOG.info("Loading aai-path.properties via OSGi");
             URL url = null;
             Bundle bundle = FrameworkUtil.getBundle(AAIService.class);
             if(bundle != null) {
@@ -176,7 +179,19 @@ public abstract class AAIRequest {
                 url = aaiService.getClass().getResource("/aai-path.properties");
             }
 
-            InputStream in = url.openStream();
+            in = url.openStream();
+        }
+        catch (NoClassDefFoundError|Exception e) {
+            LOG.info("Loading aai-path.properties from jar");
+            in = AAIRequest.class.getResourceAsStream("/aai-path.properties");
+
+        }
+
+        if (in == null) {
+            return;
+        }
+
+        try {
             Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
 
             Properties properties = new Properties();
index 9888c83..743f975 100755 (executable)
@@ -157,7 +157,7 @@ public class AAIServiceProvider implements UtilsProvider {
             Object unmasked = gs2Method.invoke(encrSvc, new Object[] { value });
             return unmasked.toString();
 
-        } catch (Exception exc) {
+        } catch (Exception|NoClassDefFoundError exc) {
             LOG.error("Failure", exc);
             return value;
         }
index 065b075..9b4751e 100644 (file)
@@ -61,14 +61,24 @@ public class NetboxProperties {
             LOG.info("Loaded {} properties from file {}", properties.size(), ccsdkConfigDir);
         } catch (Exception e) {
             try {
-                // Try to load config from jar
+                // Try to load config from jar via OSGi
                 final Bundle bundle = FrameworkUtil.getBundle(NetboxProperties.class);
                 final BundleContext ctx = bundle.getBundleContext();
                 final URL url = ctx.getBundle().getResource(NETBOX_PROPERTY_FILE_NAME);
                 InputStream inputStream = url.openStream();
                 properties.load(inputStream);
                 LOG.info("Loaded {} properties from file {}", properties.size(), NETBOX_PROPERTY_FILE_NAME);
-            } catch (IOException|NoClassDefFoundError e1) {
+            } catch (NoClassDefFoundError e1) { 
+                // Try to load config from jar via class loader
+                try (InputStream inputStream = NetboxProperties.class.getResourceAsStream("/"+NETBOX_PROPERTY_FILE_NAME)) {
+                    properties.load(inputStream);
+                } catch (Exception e2) {
+                    LOG.error("Failed to load properties for file: {} " + NETBOX_PROPERTY_FILE_NAME, e1);
+                }
+                ;
+                LOG.info("Loaded {} properties from file {}", properties.size(), NETBOX_PROPERTY_FILE_NAME);
+
+            } catch (IOException e1) {
                 LOG.error("Failed to load properties for file: {} " + NETBOX_PROPERTY_FILE_NAME, e1);
             }
         }