2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oran.dmaapadapter.configuration;
23 import java.lang.invoke.MethodHandles;
24 import java.nio.charset.Charset;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.util.Collection;
28 import java.util.Collections;
33 import org.oran.dmaapadapter.configuration.WebClientConfig.HttpProxyConfig;
34 import org.oran.dmaapadapter.repository.InfoType;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Value;
38 import org.springframework.boot.context.properties.EnableConfigurationProperties;
40 @EnableConfigurationProperties
41 public class ApplicationConfig {
43 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
46 @Value("${app.configuration-filepath}")
47 private String localConfigurationFilePath;
49 @Value("${server.ssl.key-store-type}")
50 private String sslKeyStoreType = "";
52 @Value("${server.ssl.key-store-password}")
53 private String sslKeyStorePassword = "";
55 @Value("${server.ssl.key-store}")
56 private String sslKeyStore = "";
58 @Value("${server.ssl.key-password}")
59 private String sslKeyPassword = "";
61 @Value("${app.webclient.trust-store-used}")
62 private boolean sslTrustStoreUsed = false;
64 @Value("${app.webclient.trust-store-password}")
65 private String sslTrustStorePassword = "";
67 @Value("${app.webclient.trust-store}")
68 private String sslTrustStore = "";
70 @Value("${app.webclient.http.proxy-host:\"\"}")
71 private String httpProxyHost = "";
73 @Value("${app.webclient.http.proxy-port:0}")
74 private int httpProxyPort = 0;
78 @Value("${server.port}")
79 private int localServerHttpPort;
82 @Value("${app.ics-base-url}")
83 private String icsBaseUrl;
86 @Value("${app.dmaap-adapter-base-url}")
87 private String selfUrl;
90 @Value("${app.dmaap-base-url}")
91 private String dmaapBaseUrl;
94 @Value("${app.kafka.bootstrap-servers:}")
95 private String kafkaBootStrapServers;
97 private WebClientConfig webClientConfig = null;
99 public WebClientConfig getWebClientConfig() {
100 if (this.webClientConfig == null) {
101 HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() //
102 .httpProxyHost(this.httpProxyHost) //
103 .httpProxyPort(this.httpProxyPort) //
106 this.webClientConfig = ImmutableWebClientConfig.builder() //
107 .keyStoreType(this.sslKeyStoreType) //
108 .keyStorePassword(this.sslKeyStorePassword) //
109 .keyStore(this.sslKeyStore) //
110 .keyPassword(this.sslKeyPassword) //
111 .isTrustStoreUsed(this.sslTrustStoreUsed) //
112 .trustStore(this.sslTrustStore) //
113 .trustStorePassword(this.sslTrustStorePassword) //
114 .httpProxyConfig(httpProxyConfig) //
117 return this.webClientConfig;
120 // Adapter to parse the json format of the configuration file.
121 static class ConfigFile {
122 Collection<InfoType> types;
125 public Collection<InfoType> getTypes() {
126 com.google.gson.Gson gson = new com.google.gson.GsonBuilder().create();
129 String configJson = Files.readString(Path.of(getLocalConfigurationFilePath()), Charset.defaultCharset());
130 ConfigFile configData = gson.fromJson(configJson, ConfigFile.class);
131 return configData.types;
132 } catch (Exception e) {
133 logger.error("Could not load configuration file {}", getLocalConfigurationFilePath());
134 return Collections.emptyList();