diff options
author | 2020-02-19 11:48:59 +0100 | |
---|---|---|
committer | 2020-02-24 10:56:18 +0100 | |
commit | 2edef3c2aaafba49439e20aa13eb647c67c781d5 (patch) | |
tree | bf1dd67aab8a2ed19260fb270321ccb746841f20 /certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java | |
parent | 1e81a4ebe5141878b054e72d000ac0e7f6bc3d71 (diff) |
Added validation of configuration
Fields are being validated right after reading servers details from JSON (when application starts).
Created own annotation to validate server URL with proper requirements.
When invalid details are given application closes.
Signed-off-by: Michal Banka <michal.banka@nokia.com>
Change-Id: I3e476266056ec0fb637f01f9d4d4c63b1f0d1c6a
Issue-ID: AAF-997
Diffstat (limited to 'certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java')
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java b/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java index c8415ac0..a6dd5fcf 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/configuration/CmpServersConfigLoader.java @@ -21,30 +21,45 @@ package org.onap.aaf.certservice.certification.configuration; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.File; +import java.io.IOException; +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.List; import org.onap.aaf.certservice.certification.configuration.model.CmpServers; import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server; +import org.onap.aaf.certservice.certification.configuration.validation.Cmpv2ServerConfigurationValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - @Component class CmpServersConfigLoader { + private static final Logger LOGGER = LoggerFactory.getLogger(CmpServersConfigLoader.class); + private final Cmpv2ServerConfigurationValidator validator; + + @Autowired + public CmpServersConfigLoader(Cmpv2ServerConfigurationValidator validator) { + this.validator = validator; + } + List<Cmpv2Server> load(String path) { - List<Cmpv2Server> result = new ArrayList<>(); + List<Cmpv2Server> servers = new ArrayList<>(); try { - result = loadConfigFromFile(path).getCmpv2Servers(); + servers = loadConfigFromFile(path).getCmpv2Servers(); + servers.forEach(validator::validate); LOGGER.info(String.format("CMP Servers configuration successfully loaded from file '%s'", path)); } catch (IOException e) { LOGGER.error("Exception occurred during CMP Servers configuration loading: ", e); + } catch (InvalidParameterException e) { + LOGGER.error("Validation of CMPv2 servers configuration failed:", e); + throw e; } - return result; + + return servers; } private CmpServers loadConfigFromFile(String path) throws IOException { |