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=========================================================
22 package org.onap.aai.restclient;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.http.HttpHeaders;
28 import org.springframework.http.MediaType;
29 import org.springframework.stereotype.Component;
30 import org.springframework.util.MultiValueMap;
32 import java.util.Collections;
34 import java.util.UUID;
36 @Component(value = "schema-service-rest-client")
37 public class SchemaServiceRestClient extends TwoWaySSLRestClient {
38 private static EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceRestClient.class);
40 @Value("${schema.service.base.url}")
41 private String baseUrl;
43 @Value("${schema.service.ssl.key-store}")
44 private String keystorePath;
46 @Value("${schema.service.ssl.trust-store}")
47 private String truststorePath;
49 @Value("${schema.service.ssl.key-store-password}")
50 private String keystorePassword;
52 @Value("${schema.service.ssl.trust-store-password}")
53 private String truststorePassword;
56 public String getBaseUrl() {
61 protected String getKeystorePath() {
66 protected String getTruststorePath() {
67 return truststorePath;
71 protected char[] getKeystorePassword() {
72 return keystorePassword.toCharArray();
76 protected char[] getTruststorePassword() {
77 return truststorePassword.toCharArray();
81 public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
82 HttpHeaders httpHeaders = new HttpHeaders();
84 String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString());
85 String defaultContentType = headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString());
87 if (headers.isEmpty()) {
88 httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept)));
89 httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType));
92 httpHeaders.add("X-FromAppId", appName);
93 httpHeaders.add("X-TransactionId", UUID.randomUUID().toString());
94 headers.forEach(httpHeaders::add);