2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.nbi.apis.serviceinventory;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.http.HttpEntity;
22 import org.springframework.http.HttpHeaders;
23 import org.springframework.http.HttpMethod;
24 import org.springframework.http.HttpStatus;
25 import org.springframework.http.ResponseEntity;
26 import org.springframework.web.client.RestTemplate;
28 public abstract class BaseClient {
30 private static final Logger LOGGER = LoggerFactory.getLogger(BaseClient.class);
33 private RestTemplate restTemplate;
35 protected ResponseEntity<Object> callApiGet(String callURL, HttpHeaders httpHeaders) {
37 ResponseEntity<Object> response = restTemplate.exchange(callURL, HttpMethod.GET,
38 new HttpEntity<>("parameters", httpHeaders), Object.class);
39 LOGGER.debug("response body : " + response.getBody().toString());
40 LOGGER.info("response status : " + response.getStatusCodeValue());
41 if (!response.getStatusCode().equals(HttpStatus.OK)) {
42 LOGGER.warn("HTTP call on " + callURL + " returns " + response.getStatusCodeValue() + ", "
43 + response.getBody().toString());