From 0c3063e69408fe6a0dff9f8aaf7331e271dc8984 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 10 Nov 2020 12:54:21 -0500 Subject: Fix handling of non-OSGi 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 --- .../sli/adaptors/netbox/property/NetboxProperties.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'netbox-client') diff --git a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java index 065b07551..9b4751e64 100644 --- a/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java +++ b/netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/property/NetboxProperties.java @@ -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); } } -- cgit 1.2.3-korg