package org.onap.aai.restclient;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
public abstract class RestClient {
- private static EELFLogger log = EELFManager.getInstance().getLogger(RestClient.class);
+ private static Logger log = LoggerFactory.getLogger(RestClient.class);
@Value("${spring.application.name}")
protected String appName;
/**
* Execute the given http method against the uri with passed headers
- *
+ *
* @param uri properly encoded, can include query params also properly encoded
* @param method http method of the request
* @param headers headers for the request
* @return response of request
* @throws RestClientException on internal rest template exception or invalid url
*/
- public ResponseEntity execute(String uri, HttpMethod method, Map<String, String> headers, String body)
+ public ResponseEntity<String> execute(String uri, HttpMethod method, Map<String, String> headers, String body)
throws RestClientException {
HttpEntity<String> httpEntity;
- log.debug("Headers: {}", headers);
+ log.debug("Request Headers: {}", headers);
if (body == null) {
httpEntity = new HttpEntity<>(getHeaders(headers));
} else {
log.error("URL syntax error with url {}{}", getBaseUrl(), uri);
throw new RestClientException(e.getMessage());
}
- log.debug("METHOD={},URL={},HEADERS={}", method, url, httpEntity);
-
- ResponseEntity responseEntity = getRestTemplate().exchange(url, method, httpEntity, String.class);
- log.debug("RESPONSE={}", responseEntity);
+ log.debug("METHOD={}, URL={}, BODY={}", method, url, httpEntity.getBody());
+ ResponseEntity<String> responseEntity = getRestTemplate().exchange(url, method, httpEntity, String.class);
+ log.trace("RESPONSE={}", responseEntity);
return responseEntity;
}
/**
* Execute the given http method against the uri with passed headers
- *
+ *
* @param uri properly encoded, can include query params also properly encoded
* @param method http method of the request
* @param headers headers for the request
* @return response of request
* @throws RestClientException on internal rest template exception or invalid url
*/
- public ResponseEntity execute(String uri, String method, Map<String, String> headers, String body)
+ public ResponseEntity<String> execute(String uri, String method, Map<String, String> headers, String body)
throws RestClientException {
return execute(uri, HttpMethod.valueOf(method), headers, body);
}
/**
* Execute the given http method against the uri with passed headers
- *
+ *
* @param uri properly encoded, can include query params also properly encoded
* @param method http method of the request
* @param headers headers for the request
* @return response of request
* @throws RestClientException on internal rest template exception or invalid url
*/
- public ResponseEntity execute(String uri, HttpMethod method, Map<String, String> headers)
+ public ResponseEntity<String> execute(String uri, HttpMethod method, Map<String, String> headers)
throws RestClientException {
return execute(uri, method, headers, null);
}
/**
* Execute the given http method against the uri with passed headers
- *
+ *
* @param uri properly encoded, can include query params also properly encoded
* @param method http method of the request
* @param headers headers for the request
* @return response of request
* @throws RestClientException on internal rest template exception or invalid url
*/
- public ResponseEntity execute(String uri, String method, Map<String, String> headers) throws RestClientException {
+ public ResponseEntity<String> execute(String uri, String method, Map<String, String> headers)
+ throws RestClientException {
return execute(uri, HttpMethod.valueOf(method), headers, null);
}
- public ResponseEntity executeResource(String uri, HttpMethod method, Map<String, String> headers, String body)
- throws RestClientException {
+ public ResponseEntity<Resource> executeResource(String uri, HttpMethod method, Map<String, String> headers,
+ String body) throws RestClientException {
- HttpEntity httpEntity;
+ HttpEntity<String> httpEntity;
log.debug("Headers: " + headers.toString());
if (body == null) {
httpEntity = new HttpEntity(getHeaders(headers));
return getRestTemplate().exchange(url, method, httpEntity, Resource.class);
}
- public ResponseEntity getGetRequest(String content, String uri, Map<String, String> headersMap) {
+ public ResponseEntity<String> getGetRequest(String content, String uri, Map<String, String> headersMap) {
return this.execute(uri, HttpMethod.GET, headersMap, content);
}
- public ResponseEntity getGetResource(String content, String uri, Map<String, String> headersMap) {
+ public ResponseEntity<Resource> getGetResource(String content, String uri, Map<String, String> headersMap) {
return this.executeResource(uri, HttpMethod.GET, headersMap, content);
}