2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.aai.prevalidation;
25 import org.onap.aai.restclient.TwoWaySSLRestClient;
26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.http.HttpHeaders;
28 import org.springframework.http.MediaType;
29 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
30 import org.springframework.util.MultiValueMap;
32 import java.util.Collections;
34 import java.util.UUID;
36 public class ValidationServiceRestClient extends TwoWaySSLRestClient {
38 @Value("${validation.service.base.url}")
39 private String baseUrl;
41 @Value("${validation.service.ssl.key-store}")
42 private String keystorePath;
44 @Value("${validation.service.ssl.trust-store}")
45 private String truststorePath;
47 @Value("${validation.service.ssl.key-store-password}")
48 private String keystorePassword;
50 @Value("${validation.service.ssl.trust-store-password}")
51 private String truststorePassword;
53 @Value("${validation.service.timeout-in-milliseconds}")
54 private Integer timeout;
57 public String getBaseUrl() {
62 protected String getKeystorePath() {
67 protected String getTruststorePath() {
68 return truststorePath;
72 protected char[] getKeystorePassword() {
73 return keystorePassword.toCharArray();
77 protected char[] getTruststorePassword() {
78 return truststorePassword.toCharArray();
81 protected HttpComponentsClientHttpRequestFactory getHttpRequestFactory() throws Exception {
82 HttpComponentsClientHttpRequestFactory requestFactory = super.getHttpRequestFactory();
83 requestFactory.setConnectionRequestTimeout(timeout);
84 requestFactory.setReadTimeout(timeout);
85 requestFactory.setConnectTimeout(timeout);
86 return requestFactory;
90 public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
91 HttpHeaders httpHeaders = new HttpHeaders();
93 String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString());
94 String defaultContentType =
95 headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString());
97 if (headers.isEmpty()) {
98 httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept)));
99 httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType));
102 httpHeaders.add("X-FromAppId", appName);
103 httpHeaders.add("X-TransactionId", UUID.randomUUID().toString());
104 headers.forEach(httpHeaders::add);