30d872f5dea889c999bb0f74b182f53614c1b911
[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 com.fasterxml.jackson.databind.ObjectMapper;
21 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
22 import javax.ws.rs.client.Client;
23 import javax.ws.rs.client.ClientBuilder;
24 import org.glassfish.jersey.client.ClientConfig;
25 import org.glassfish.jersey.client.ClientProperties;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.stereotype.Component;
30
31 @Component
32 public class CallbackConfiguration {
33     /** Use same object mapper as embedded tomcat server */
34     @Autowired
35     private ObjectMapper objectMapper;
36
37     @Value("${callback.keyStorePath:}")
38     private String keyStorePath;
39
40     @Value("${callback.keyStorePassword:}")
41     private String keyStorePassword;
42
43     @Value("${callback.connectionTimeout:5000}")
44     private int connectionTimeout;
45
46     @Value("${callback.readTimeout:60000}")
47     private int readTimeout;
48
49     @Value("${callback.username:}")
50     private String basicAuthUsername;
51
52     @Value("${callback.password:}")
53     private String basicAuthPassword;
54
55     @Bean(name="callbackClient")
56     public Client getClient() throws Exception {
57         ClientConfig configuration = new ClientConfig()
58                 .property(ClientProperties.CONNECT_TIMEOUT, this.connectionTimeout)
59                 .property(ClientProperties.READ_TIMEOUT, this.readTimeout)
60                 .register(new JacksonJaxbJsonProvider(objectMapper, null));
61
62         // TODO set up SSL if configured
63 //      if (useSsl) {
64 //      setupSecureSocketLayerClientConfig(clientConfig);
65 //  }
66         // Finally, create and initialize our client...
67         Client client = ClientBuilder.newClient(configuration);
68
69         // ...and return it to the caller.
70         return client;
71     }
72
73
74 }