2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.controllers;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import io.joshworks.restclient.http.mapper.ObjectMapper;
26 import java.io.IOException;
27 import org.onap.vid.aai.AaiClient;
28 import org.onap.vid.aai.AaiClientInterface;
29 import org.onap.vid.aai.AaiOverTLSClient;
30 import org.onap.vid.aai.AaiOverTLSClientInterface;
31 import org.onap.vid.aai.AaiOverTLSPropertySupplier;
32 import org.onap.vid.aai.AaiResponseTranslator;
33 import org.onap.vid.aai.PombaClientImpl;
34 import org.onap.vid.aai.PombaClientInterface;
35 import org.onap.vid.aai.PombaRestInterface;
36 import org.onap.vid.aai.model.PortDetailsTranslator;
37 import org.onap.vid.aai.util.AAIRestInterface;
38 import org.onap.vid.aai.util.HttpsAuthClient;
39 import org.onap.vid.aai.util.SSLContextProvider;
40 import org.onap.vid.aai.util.ServletRequestHelper;
41 import org.onap.vid.aai.util.SystemPropertyHelper;
42 import org.onap.vid.asdc.AsdcClient;
43 import org.onap.vid.asdc.parser.ToscaParserImpl2;
44 import org.onap.vid.asdc.rest.SdcRestClient;
45 import org.onap.vid.client.SyncRestClient;
46 import org.onap.vid.client.SyncRestClientInterface;
47 import org.onap.vid.properties.AsdcClientConfiguration;
48 import org.onap.vid.services.AaiService;
49 import org.onap.vid.services.AaiServiceImpl;
50 import org.onap.vid.services.PombaService;
51 import org.onap.vid.services.PombaServiceImpl;
52 import org.onap.vid.services.VidService;
53 import org.onap.vid.services.VidServiceImpl;
54 import org.onap.vid.scheduler.SchedulerRestInterface;
55 import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
56 import org.springframework.beans.factory.annotation.Qualifier;
57 import org.springframework.context.annotation.Bean;
58 import org.springframework.context.annotation.Configuration;
59 import org.togglz.core.manager.FeatureManager;
61 import javax.servlet.ServletContext;
65 public class WebConfig {
68 * Gets the object mapper.
70 * @return the object mapper
73 public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
74 return new com.fasterxml.jackson.databind.ObjectMapper();
79 public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
80 return new VidServiceImpl(asdcClient, featureManager);
84 public AaiService getAaiService() {
85 return new AaiServiceImpl();
89 public AaiResponseTranslator aaiResponseTranslator() {
90 return new AaiResponseTranslator();
94 public PortDetailsTranslator portDetailsTranslator() {
95 return new PortDetailsTranslator();
99 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator) {
100 return new AaiClient(restController, portsDetailsTranslator);
103 @Bean(name = "aaiRestInterface")
104 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
105 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
109 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
110 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
114 public SSLContextProvider sslContextProvider() {
115 return new SSLContextProvider();
119 public SystemPropertyHelper systemPropertyHelper() {
120 return new SystemPropertyHelper();
124 public ServletRequestHelper servletRequestHelper() {
125 return new ServletRequestHelper();
129 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) {
130 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
131 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider);
135 public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
136 String auth = asdcClientConfiguration.getAsdcClientAuth();
137 String host = asdcClientConfiguration.getAsdcClientHost();
138 String protocol = asdcClientConfiguration.getAsdcClientProtocol();
139 int port = asdcClientConfiguration.getAsdcClientPort();
141 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
145 public SyncRestClientInterface syncRestClient() {
146 return new SyncRestClient();
150 public ToscaParserImpl2 getToscaParser() {
151 return new ToscaParserImpl2();
155 public PombaService getVerifyServiceInstanceService() {
156 return new PombaServiceImpl();
160 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
161 return new PombaClientImpl();
165 public SchedulerRestInterfaceIfc getSchedulerRestInterface(){
166 return new SchedulerRestInterface();
169 @Bean(name = "aaiClientForFasterXmlMapping")
170 public AaiOverTLSClientInterface getAaiClientForFasterXmlMapping(){
171 ObjectMapper objectMapper = new ObjectMapper() {
173 com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
176 public <T> T readValue(String s, Class<T> aClass) {
178 return om.readValue(s, aClass);
179 } catch (IOException e) {
180 throw new RuntimeException(e);
185 public String writeValue(Object o) {
187 return om.writeValueAsString(o);
188 } catch (JsonProcessingException e) {
189 throw new RuntimeException(e);
194 return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
198 @Bean(name = "aaiClientForCodehausMapping")
199 public AaiOverTLSClientInterface getAaiClientForCodehausMapping() {
201 ObjectMapper objectMapper = new ObjectMapper() {
203 org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper();
206 public <T> T readValue(String s, Class<T> aClass) {
208 return om.readValue(s, aClass);
209 } catch (IOException e) {
210 throw new RuntimeException(e);
215 public String writeValue(Object o) {
217 return om.writeValueAsString(o);
218 } catch (IOException e) {
219 throw new RuntimeException(e);
224 return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());