summaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/main/java
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-06-11 13:39:31 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-06-12 08:24:43 +0200
commit09893f98631753467a9c2ec8c591b917c0bc25c4 (patch)
tree6057670c6e40bea850c4d04cf762543564febf7e /prh-aai-client/src/main/java
parentdabda661a59fb07c640bfe96bfc4675e3b10f04f (diff)
handleResponse refactor
Due to logs consistency handleResponse method was incorporated to the each of http producers. Change-Id: I621d1795c376161273270f07ff3dd6caca2fc1d6 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-aai-client/src/main/java')
-rw-r--r--prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java
index f9c2708e..f85ac8aa 100644
--- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java
+++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/prh/service/AAIProducerClient.java
@@ -20,14 +20,18 @@
package org.onap.dcaegen2.services.prh.service;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
import org.onap.dcaegen2.services.prh.model.CommonFunctions;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.model.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,7 +74,7 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
public Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException {
return createRequest(consumerDmaapModel).flatMap(httpRequestBase -> {
try {
- return closeableHttpClient.execute(httpRequestBase, CommonFunctions::handleResponse);
+ return closeableHttpClient.execute(httpRequestBase, this::handleResponse);
} catch (IOException e) {
logger.warn(EXCEPTION_MESSAGE, e);
return Optional.empty();
@@ -115,4 +119,20 @@ public class AAIProducerClient implements AAIExtendedHttpClient {
return Base64.getEncoder().encodeToString((this.aaiUserName + ":" + this.aaiUserPassword)
.getBytes("UTF-8"));
}
+
+ Optional<Integer> handleResponse(HttpResponse response) throws IOException {
+
+ final Integer responseCode = response.getStatusLine().getStatusCode();
+ logger.info("Status code of operation: {}", responseCode);
+ final HttpEntity responseEntity = response.getEntity();
+
+ if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
+ logger.trace("HTTP response successful.");
+ return Optional.of(responseCode);
+ } else {
+ String aaiResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
+ logger.warn("HTTP response not successful : {}", aaiResponse);
+ return Optional.of(responseCode);
+ }
+ }
}