2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================
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.onap.dcaegen2.services.prh.configuration;
23 import com.google.gson.Gson;
24 import java.io.InputStream;
25 import java.io.InputStreamReader;
26 import java.nio.charset.StandardCharsets;
28 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
29 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.core.io.Resource;
34 import org.springframework.stereotype.Component;
35 import reactor.core.publisher.Mono;
38 public class CbsClientConfigFileReader {
40 private static final Logger LOGGER = LoggerFactory.getLogger(CbsClientConfigFileReader.class);
42 private final Resource cbsClientConfigFile;
44 public CbsClientConfigFileReader(@Value("classpath:cbs_client_config.json") Resource cbsClientConfigFile) {
45 this.cbsClientConfigFile = cbsClientConfigFile;
48 public Mono<CbsClientConfiguration> readConfig() {
49 LOGGER.debug("Loading CBS client configuration from configuration file");
50 try (InputStream inputStream = cbsClientConfigFile.getInputStream()) {
51 CbsClientConfiguration config = new Gson().fromJson(
52 new InputStreamReader(inputStream, StandardCharsets.UTF_8), ImmutableCbsClientConfiguration.class);
53 LOGGER.info("Evaluated variables: {}", config);
54 return Mono.just(config);
55 } catch (Exception e) {
56 return Mono.error(new RuntimeException("Failed to load/parse CBS client configuration file", e));