From 30510151ca3575cb079aba0ea34567add7c52526 Mon Sep 17 00:00:00 2001 From: Dmitry Puzikov Date: Tue, 19 Nov 2019 15:13:23 +0100 Subject: Fixing sonar issues Replaced URL with URI to avoid trigger DNS. Change-Id: If85f1f2780c46e0966f3707af51571f4a7aa2f15 Issue-ID: SDC-2660 Signed-off-by: Dmitry Puzikov --- .../java/org/onap/config/NonConfigResource.java | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'common/onap-common-configuration-management') diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java index 459c8b476b..065e7f42b4 100644 --- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java +++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java @@ -17,6 +17,7 @@ package org.onap.config; import java.io.File; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -36,9 +37,9 @@ public class NonConfigResource { static final String CONFIG_LOCATION = "config.location"; private final List> lookupFunctions = - Arrays.asList(this::getFromFile, this::findInFiles, this::getForNode, this::getGlobal, this::findInUrls); + Arrays.asList(this::getFromFile, this::findInFiles, this::getForNode, this::getGlobal, this::findInUris); - private final Set urls = Collections.synchronizedSet(new HashSet<>()); + private final Set uris = Collections.synchronizedSet(new HashSet<>()); private final Set files = Collections.synchronizedSet(new HashSet<>()); private final Function propertyGetter; @@ -52,7 +53,7 @@ public class NonConfigResource { } public void add(URL url) { - urls.add(url); + uris.add(toUri(url)); } public void add(File file) { @@ -96,15 +97,12 @@ public class NonConfigResource { return new File(resource).exists() ? Paths.get(resource) : null; } - private Path findInUrls(String resource) { - - for (URL url : urls) { - - if (url.getFile().endsWith(resource)) { - return Paths.get(toUri(url)); + private Path findInUris(String resource) { + for (URI uri : uris) { + if (toUrl(uri).getFile().endsWith(resource)) { + return Paths.get(uri); } } - return null; } @@ -139,7 +137,15 @@ public class NonConfigResource { try { return url.toURI(); } catch (URISyntaxException e) { - throw new IllegalStateException("Unexpected URL syntax: " + url.toString(), e); + throw new IllegalStateException("Unexpected URL syntax: " + url, e); + } + } + + private static URL toUrl(URI uri) { + try { + return uri.toURL(); + } catch (MalformedURLException e) { + throw new IllegalStateException("Unexpected URI syntax: " + uri, e); } } } -- cgit 1.2.3-korg