0a0857766f3effbec1f124112d1d56445de7bd24
[sdnc/apps.git] /
1 /*
2  * ============LICENSE_START===================================================
3  * Copyright (c) 2018 Amdocs
4  * ============================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=====================================================
17  */
18 package org.onap.sdnc.apps.pomba.networkdiscovery;
19
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.StringTokenizer;
23 import org.onap.aai.restclient.client.RestClient;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.beans.factory.annotation.Value;
26 import org.springframework.context.annotation.Bean;
27 import org.springframework.context.annotation.Configuration;
28 import org.springframework.core.env.Environment;
29
30 @Configuration
31 public class EnricherConfiguration {
32     @Autowired 
33     private Environment env;
34     
35         @Value("${enricher.url}")
36         private String url;
37
38         @Value("${enricher.keyStorePath}")
39         private String keyStorePath;
40
41         @Value("${enricher.keyStorePassword}")
42         private String keyStorePassword;
43
44         @Value("${enricher.connectionTimeout:5000}")
45         private int connectionTimeout;
46
47         @Value("${enricher.readTimeout:60000}")
48         private int readTimeout;
49
50         @Bean(name="enricherClient")
51         public RestClient restClient() {
52                 return new RestClient()
53                         .validateServerHostname(false)
54                         .validateServerCertChain(false)
55                         .connectTimeoutMs(this.connectionTimeout)
56                         .readTimeoutMs(this.readTimeout)
57                 .clientCertFile(this.keyStorePath)
58                 .clientCertPassword(this.keyStorePassword);
59         }
60
61         @Bean(name="enricherBaseUrl")
62         public String getURL() {
63                 return this.url;
64         }
65         
66         @Bean(name="enricherTypeURLs")
67         public Map<String, String> enricherTypeURLs() {
68
69             Map<String, String> result = new HashMap<>();
70             String types = this.env.getProperty("enricher.types");
71             if (types == null) {
72                 return result;
73             }
74             
75             StringTokenizer tokenizer = new StringTokenizer(types, ", ");
76             while (tokenizer.hasMoreTokens()) {
77                 String type = tokenizer.nextToken();
78                 String url = this.env.getProperty("enricher.type." + type + ".url");
79                 result.put(type, url);
80             }
81             
82         return result;
83         }
84
85
86 }