2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018-19 AT&T 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.aai.prevalidation;
23 import java.util.Collections;
25 import java.util.UUID;
27 import org.onap.aai.restclient.NoAuthRestClient;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Value;
31 import org.springframework.http.HttpHeaders;
32 import org.springframework.http.MediaType;
33 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
34 import org.springframework.util.MultiValueMap;
36 public class ValidationServiceNoAuthClient extends NoAuthRestClient {
38 private static Logger logger = LoggerFactory.getLogger(ValidationServiceNoAuthClient.class);
40 @Value("${validation.service.base.url}")
41 private String baseUrl;
43 @Value("${validation.service.timeout-in-milliseconds}")
44 private Integer timeout;
47 protected HttpComponentsClientHttpRequestFactory getHttpRequestFactory() throws Exception {
48 HttpComponentsClientHttpRequestFactory requestFactory = super.getHttpRequestFactory();
49 requestFactory.setConnectionRequestTimeout(timeout);
50 requestFactory.setReadTimeout(timeout);
51 requestFactory.setConnectTimeout(timeout);
52 return requestFactory;
56 public String getBaseUrl() {
61 public MultiValueMap<String, String> getHeaders(Map<String, String> headers) {
62 HttpHeaders httpHeaders = new HttpHeaders();
64 String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString());
65 String defaultContentType =
66 headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString());
68 if (headers.isEmpty()) {
69 httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept)));
70 httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType));
73 httpHeaders.add("X-FromAppId", appName);
74 httpHeaders.add("X-TransactionId", UUID.randomUUID().toString());
75 headers.forEach(httpHeaders::add);