2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
4 * ================================================================================
5 * Copyright (C) 2018-2019 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.sdk.rest.services.aai.client.service;
23 import java.nio.file.Paths;
24 import java.util.UUID;
25 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
26 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
27 import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClientFactory;
28 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext;
29 import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
30 import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys;
31 import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore;
32 import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
33 import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class AaiHttpClientFactory {
39 private static final Logger LOGGER = LoggerFactory.getLogger(AaiHttpClientFactory.class);
41 private final AaiClientConfiguration configuration;
43 public AaiHttpClientFactory(AaiClientConfiguration configuration) {
44 this.configuration = configuration;
47 public RxHttpClient build() {
48 LOGGER.debug("Setting ssl context");
50 if (configuration.enableAaiCertAuth()) {
51 return RxHttpClientFactory.create(createSslKeys());
53 return RxHttpClientFactory.createInsecure();
57 private SecurityKeys createSslKeys() {
58 return ImmutableSecurityKeys.builder()
59 .keyStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.keyStorePath())))
60 .keyStorePassword(Passwords.fromPath(Paths.get(configuration.keyStorePasswordPath())))
61 .trustStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.trustStorePath())))
62 .trustStorePassword(Passwords.fromPath(Paths.get(configuration.trustStorePasswordPath())))
66 public static RequestDiagnosticContext createRequestDiagnosticContext() {
67 return ImmutableRequestDiagnosticContext.builder()
68 .invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build();