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.databind.ObjectMapper;
25 import org.onap.vid.aai.*;
26 import org.onap.vid.aai.model.PortDetailsTranslator;
27 import org.onap.vid.aai.util.*;
28 import org.onap.vid.asdc.AsdcClient;
29 import org.onap.vid.asdc.parser.ToscaParserImpl2;
30 import org.onap.vid.asdc.rest.RestfulAsdcClient;
31 import org.onap.vid.exceptions.GenericUncheckedException;
32 import org.onap.vid.properties.AsdcClientConfiguration;
33 import org.onap.vid.scheduler.SchedulerRestInterface;
34 import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
35 import org.onap.vid.services.*;
36 import org.springframework.beans.factory.annotation.Qualifier;
37 import org.springframework.context.annotation.Bean;
38 import org.springframework.context.annotation.Configuration;
39 import org.togglz.core.manager.FeatureManager;
41 import javax.net.ssl.SSLContext;
42 import javax.servlet.ServletContext;
43 import javax.ws.rs.client.Client;
44 import javax.ws.rs.client.ClientBuilder;
47 import java.net.URISyntaxException;
48 import java.security.KeyManagementException;
49 import java.security.NoSuchAlgorithmException;
52 public class WebConfig {
55 * Gets the object mapper.
57 * @return the object mapper
60 public ObjectMapper getObjectMapper() {
61 return new ObjectMapper();
66 public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
67 return new VidServiceImpl(asdcClient, featureManager);
71 public AaiService getAaiService() {
72 return new AaiServiceImpl();
76 public AaiResponseTranslator aaiResponseTranslator() {
77 return new AaiResponseTranslator();
81 public PortDetailsTranslator portDetailsTranslator() {
82 return new PortDetailsTranslator();
86 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator) {
87 return new AaiClient(restController, portsDetailsTranslator);
90 @Bean(name = "aaiRestInterface")
91 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
92 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
96 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
97 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
101 public SSLContextProvider sslContextProvider() {
102 return new SSLContextProvider();
106 public SystemPropertyHelper systemPropertyHelper() {
107 return new SystemPropertyHelper();
111 public ServletRequestHelper servletRequestHelper() {
112 return new ServletRequestHelper();
116 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) {
117 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
118 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider);
122 public AsdcClient asdcClient(AsdcClientConfiguration asdcClientConfig) {
124 final String protocol = asdcClientConfig.getAsdcClientProtocol();
125 final String host = asdcClientConfig.getAsdcClientHost();
126 final int port = asdcClientConfig.getAsdcClientPort();
127 final String auth = asdcClientConfig.getAsdcClientAuth();
129 if (protocol.equalsIgnoreCase("https")) {
131 SSLContext ctx = SSLContext.getInstance("TLSv1.2");
132 ctx.init(null, null, null);
133 cl = ClientBuilder.newBuilder().sslContext(ctx).build();
134 } catch (NoSuchAlgorithmException n) {
135 throw new GenericUncheckedException("SDC Client could not be instantiated due to unsupported protocol TLSv1.2", n);
136 } catch (KeyManagementException k) {
137 throw new GenericUncheckedException("SDC Client could not be instantiated due to a key management exception", k);
140 cl = ClientBuilder.newBuilder().build();
144 final URI uri = new URI(protocol + "://" + host + ":" + port + "/");
145 return new RestfulAsdcClient.Builder(cl, uri)
148 } catch (URISyntaxException e) {
149 throw new GenericUncheckedException("SDC Client could not be instantiated due to a syntax error in the URI", e);
154 public ToscaParserImpl2 getToscaParser() {
155 return new ToscaParserImpl2();
159 public PombaService getVerifyServiceInstanceService() {
160 return new PombaServiceImpl();
164 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
165 return new PombaClientImpl();
169 public SchedulerRestInterfaceIfc getSchedulerRestInterface(){
170 return new SchedulerRestInterface();