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.core.io.Resource;
28 import org.springframework.http.HttpEntity;
29 import org.springframework.http.HttpMethod;
30 import org.springframework.http.ResponseEntity;
31 import org.springframework.util.MultiValueMap;
32 import org.springframework.web.client.RestClientException;
33 import org.springframework.web.client.RestTemplate;
37 public abstract class RestClient {
39 private static EELFLogger log = EELFManager.getInstance().getLogger(RestClient.class);
40 @Value("${spring.application.name}")
41 protected String appName;
43 public ResponseEntity execute(String uri, HttpMethod method, Map<String, String> headers, String body) throws RestClientException {
45 HttpEntity httpEntity;
46 log.debug("Headers: " + headers.toString());
48 httpEntity = new HttpEntity(getHeaders(headers));
50 httpEntity = new HttpEntity(body, getHeaders(headers));
52 String url = getBaseUrl() + uri;
53 return getRestTemplate().exchange(url, method, httpEntity, String.class);
56 public ResponseEntity executeResource(String uri, HttpMethod method, Map<String, String> headers, String body) throws RestClientException {
58 HttpEntity httpEntity;
59 log.debug("Headers: " + headers.toString());
61 httpEntity = new HttpEntity(getHeaders(headers));
63 httpEntity = new HttpEntity(body, getHeaders(headers));
65 String url = getBaseUrl() + uri;
66 return getRestTemplate().exchange(url, method, httpEntity, Resource.class);
69 public ResponseEntity execute(String uri, String method, Map<String, String> headers) throws RestClientException {
70 return execute(uri, HttpMethod.valueOf(method), headers, null);
73 public ResponseEntity getGetRequest(String content, String uri, Map<String, String> headersMap) {
82 public ResponseEntity getGetResource(String content, String uri, Map<String, String> headersMap) {
83 return this.executeResource(
91 public abstract RestTemplate getRestTemplate();
93 public abstract String getBaseUrl();
95 protected abstract MultiValueMap<String, String> getHeaders(Map<String, String> headers);
97 protected abstract EELFLogger getLogger();