diff options
Diffstat (limited to 'certServiceClient/src/main/java')
-rw-r--r-- | certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java index 603d5848..30f881bb 100644 --- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java +++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java @@ -57,12 +57,14 @@ public class HttpClient { throws CertServiceApiResponseException, HttpClientException { try (CloseableHttpClient httpClient = httpClientProvider.getClient()) { - HttpResponse httpResponse = httpClient.execute(createHttpPayload(caName, csr, encodedPk)); + LOGGER.info("Sending request to API. Url: {}{} ", certServiceAddress, caName); + HttpResponse httpResponse = httpClient.execute(createHttpRequest(caName, csr, encodedPk)); + LOGGER.info("Received response from API"); return extractCertServiceResponse(httpResponse); } catch (IOException e) { - LOGGER.error(String.format("Failed on communication between client and API for URL: '%s' . Exception message: '%s'", - certServiceAddress + caName, e.getMessage())); + LOGGER.error("Failed execute request to API for URL: {}{} . Exception message: {}", + certServiceAddress, caName, e.getMessage()); throw new HttpClientException(e); } } @@ -72,21 +74,26 @@ public class HttpClient { } private CertServiceResponse extractCertServiceResponse(HttpResponse httpResponse) - throws CertServiceApiResponseException, IOException { + throws CertServiceApiResponseException, HttpClientException { int httpResponseCode = getStatusCode(httpResponse); if (HttpStatus.SC_OK != httpResponseCode) { - LOGGER.error(String.format("Error on API response. Response Code: %d", httpResponseCode)); + LOGGER.error("Error on API response. Response Code: {}", httpResponseCode); throw generateApiResponseException(httpResponse); } String jsonResponse = getStringResponse(httpResponse.getEntity()); return gson.fromJson(jsonResponse, CertServiceResponse.class); } - private String getStringResponse(HttpEntity httpEntity) throws IOException { - return EntityUtils.toString(httpEntity, CHARSET_UTF_8); + private String getStringResponse(HttpEntity httpEntity) throws HttpClientException { + try { + return EntityUtils.toString(httpEntity, CHARSET_UTF_8); + } catch (IOException e) { + LOGGER.error("Cannot parse response to string", e); + throw new HttpClientException(e); + } } - private HttpGet createHttpPayload(String caName, String csr, String pk) { + private HttpGet createHttpRequest(String caName, String csr, String pk) { String url = certServiceAddress + caName; HttpGet httpGet = new HttpGet(url); httpGet.addHeader(CSR_HEADER_NAME, csr); @@ -95,7 +102,8 @@ public class HttpClient { } - private CertServiceApiResponseException generateApiResponseException(HttpResponse httpResponse) throws IOException { + private CertServiceApiResponseException generateApiResponseException(HttpResponse httpResponse) + throws HttpClientException { String stringResponse = getStringResponse(httpResponse.getEntity()); ErrorCertServiceResponse errorCertServiceResponse = gson.fromJson(stringResponse, ErrorCertServiceResponse.class); |