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.http.converter.StringHttpMessageConverter;
27 import org.springframework.web.client.RestTemplate;
29 public abstract class BaseClient {
31 private static final Logger LOGGER = LoggerFactory.getLogger(BaseClient.class);
35 private RestTemplate restTemplate;
39 protected ResponseEntity<Object> callApiGet(String callURL, HttpHeaders httpHeaders) {
42 if(LOGGER.isDebugEnabled()){
43 LOGGER.debug("log request : "+callURL+ " "+httpHeaders);
46 ResponseEntity<Object> response = null;
47 response = restTemplate.exchange(callURL, HttpMethod.GET,
48 new HttpEntity<>("parameters", httpHeaders), Object.class);
50 if(LOGGER.isDebugEnabled()){
51 LOGGER.debug("response body : {}",response.getBody().toString());
53 LOGGER.info("response status : {}", response.getStatusCodeValue());
54 if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
55 LOGGER.warn("HTTP call on {} returns {}, {}", callURL , response.getStatusCodeValue() ,response.getBody().toString());
61 protected ResponseEntity<String> callApiGetHealthCheck(String callURL, HttpHeaders httpHeaders) {
64 if(LOGGER.isDebugEnabled()){
65 LOGGER.debug("log request : "+callURL+ " "+httpHeaders);
68 ResponseEntity<String> response = null;
69 response = restTemplate.exchange(callURL, HttpMethod.GET,
70 new HttpEntity<>("parameters", httpHeaders), String.class);
72 if(LOGGER.isDebugEnabled()){
73 LOGGER.debug("response body : {}",response.getBody().toString());
75 LOGGER.info("response status : {}", response.getStatusCodeValue());
76 if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
77 LOGGER.warn("HTTP call on {} returns {}, {}", callURL , response.getStatusCodeValue() ,response.getBody().toString());