diff options
author | 2018-05-23 15:31:11 +0200 | |
---|---|---|
committer | 2018-05-24 11:50:34 +0200 | |
commit | 7ddaf390698fe5ae9143d91e7011059b3973f8ce (patch) | |
tree | 4d483f24c6b73ce2e0d0a8237410856f8e01edb6 /prh-dmaap-client/src/main | |
parent | b6bc8925a354825545b8527879e0f687b0dbab3a (diff) |
Refactor of prh-aai-client
Change-Id: Idbca6fe4c050c789f4479164846437039d3b549d
Issue-ID: DCAEGEN2-451
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src/main')
-rw-r--r-- | prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImpl.java | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImpl.java index 72e70b98..b93c9c6b 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImpl.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImpl.java @@ -20,27 +20,24 @@ package org.onap.dcaegen2.services.prh.service.producer; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Optional; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; 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.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.prh.model.CommonFunctions; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.DmaapHttpClientImpl; -import org.onap.dcaegen2.services.prh.service.HttpUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Optional; + public class ExtendedDmaapProducerHttpClientImpl { private static Logger logger = LoggerFactory.getLogger(ExtendedDmaapProducerHttpClientImpl.class); @@ -63,7 +60,7 @@ public class ExtendedDmaapProducerHttpClientImpl { this.dmaapContentType = configuration.dmaapContentType(); } - public Optional<String> getHttpProducerResponse(ConsumerDmaapModel consumerDmaapModel) { + public Optional<Integer> getHttpProducerResponse(ConsumerDmaapModel consumerDmaapModel) { this.consumerDmaapModel = consumerDmaapModel; try { return createRequest() @@ -74,9 +71,9 @@ public class ExtendedDmaapProducerHttpClientImpl { return Optional.empty(); } - private Optional<String> executeHttpClient(HttpRequestBase httpRequestBase) { + private Optional<Integer> executeHttpClient(HttpRequestBase httpRequestBase) { try { - return closeableHttpClient.execute(httpRequestBase, this::getDmaapProducerResponseHandler); + return closeableHttpClient.execute(httpRequestBase, CommonFunctions::handleResponse); } catch (IOException e) { logger.warn("Exception while executing HTTP request: ", e); } @@ -112,19 +109,4 @@ public class ExtendedDmaapProducerHttpClientImpl { } return Optional.empty(); } - - private Optional<String> getDmaapProducerResponseHandler(HttpResponse httpResponse) throws IOException { - final int responseCode = httpResponse.getStatusLine().getStatusCode(); - logger.info("Status code of operation: {}", responseCode); - final HttpEntity responseEntity = httpResponse.getEntity(); - - if (HttpUtils.isSuccessfulResponseCode(responseCode)) { - logger.trace("HTTP response successful."); - return Optional.of("" + responseCode); - } else { - String response = responseEntity != null ? EntityUtils.toString(responseEntity) : ""; - logger.trace("HTTP response not successful : {}", response); - return Optional.of("" + responseCode); - } - } }
\ No newline at end of file |