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 java.util.Collections;
27 import java.util.UUID;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Value;
32 import org.springframework.http.HttpHeaders;
33 import org.springframework.http.MediaType;
34 import org.springframework.util.MultiValueMap;
36 public class SchemaServiceRestClient extends TwoWaySSLRestClient {
37 private static Logger logger = LoggerFactory.getLogger(SchemaServiceRestClient.class);
39 @Value("${schema.service.base.url}")
40 private String baseUrl;
42 @Value("${schema.service.ssl.key-store}")
43 private String keystorePath;
45 @Value("${schema.service.ssl.trust-store}")
46 private String truststorePath;
48 @Value("${schema.service.ssl.key-store-password}")
49 private String keystorePassword;
51 @Value("${schema.service.ssl.trust-store-password}")
52 private String truststorePassword;
55 public String getBaseUrl() {
60 protected String getKeystorePath() {
65 protected String getTruststorePath() {
66 return truststorePath;
70 protected char[] getKeystorePassword() {
71 return keystorePassword.toCharArray();
75 protected char[] getTruststorePassword() {
76 return truststorePassword.toCharArray();
80 public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
81 HttpHeaders httpHeaders = new HttpHeaders();
83 String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString());
84 String defaultContentType =
85 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);