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.restclient;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
28 import java.util.Collections;
30 import java.util.UUID;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.http.HttpHeaders;
34 import org.springframework.http.MediaType;
35 import org.springframework.stereotype.Component;
36 import org.springframework.util.MultiValueMap;
38 @Component(value = "schema-service-rest-client")
39 public class SchemaServiceRestClient extends TwoWaySSLRestClient {
40 private static EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceRestClient.class);
42 @Value("${schema.service.base.url}")
43 private String baseUrl;
45 @Value("${schema.service.ssl.key-store}")
46 private String keystorePath;
48 @Value("${schema.service.ssl.trust-store}")
49 private String truststorePath;
51 @Value("${schema.service.ssl.key-store-password}")
52 private String keystorePassword;
54 @Value("${schema.service.ssl.trust-store-password}")
55 private String truststorePassword;
58 public String getBaseUrl() {
63 protected String getKeystorePath() {
68 protected String getTruststorePath() {
69 return truststorePath;
73 protected char[] getKeystorePassword() {
74 return keystorePassword.toCharArray();
78 protected char[] getTruststorePassword() {
79 return truststorePassword.toCharArray();
83 public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
84 HttpHeaders httpHeaders = new HttpHeaders();
86 String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString());
87 String defaultContentType =
88 headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString());
90 if (headers.isEmpty()) {
91 httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept)));
92 httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType));
95 httpHeaders.add("X-FromAppId", appName);
96 httpHeaders.add("X-TransactionId", UUID.randomUUID().toString());
97 headers.forEach(httpHeaders::add);