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);
34 private RestTemplate restTemplate;
38 protected ResponseEntity<Object> callApiGet(String callURL, HttpHeaders httpHeaders) {
41 if(LOGGER.isDebugEnabled()){
42 LOGGER.debug("log request : "+callURL+ " "+httpHeaders);
45 ResponseEntity<Object> response = null;
46 response = restTemplate.exchange(callURL, HttpMethod.GET,
47 new HttpEntity<>("parameters", httpHeaders), Object.class);
49 if(LOGGER.isDebugEnabled()){
50 LOGGER.debug("response body : {}",response.getBody().toString());
52 LOGGER.info("response status : {}", response.getStatusCodeValue());
53 if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
54 LOGGER.warn("HTTP call on {} returns {}, {}", callURL , response.getStatusCodeValue() ,response.getBody().toString());