diff options
author | wasala <przemyslaw.wasala@nokia.com> | 2018-05-08 13:48:44 +0200 |
---|---|---|
committer | wasala <przemyslaw.wasala@nokia.com> | 2018-05-09 14:20:35 +0200 |
commit | 44ce56cf2e6bfae17c443901ac6ded8ba8cdd414 (patch) | |
tree | d2700e58cff23035f8f489ef7579ecee04ef3cc6 /prh-dmaap-client/src/main | |
parent | 7e7aa0c165665f74b628ba5c95fb3cdae72f4449 (diff) |
Added dmaap consumer task execution to workflow
Change-Id: I67904a8ffb7d401fa2188fb046e28474eded4377
Issue-ID: DCAEGEN2-474
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src/main')
4 files changed, 22 insertions, 36 deletions
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java index 525e1326..ac26ea97 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java @@ -26,7 +26,6 @@ import org.springframework.stereotype.Component; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 */ -@Component @Value.Immutable(prehash = true) @Value.Style(builder = "new") @Gson.TypeAdapters diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java index 0b76ccaa..1772104a 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java @@ -53,7 +53,7 @@ public class ExtendedDmaapConsumerHttpClientImpl { private final String dmaapContentType; - ExtendedDmaapConsumerHttpClientImpl(DmaapConsumerConfiguration configuration) { + public ExtendedDmaapConsumerHttpClientImpl(DmaapConsumerConfiguration configuration) { this.closeableHttpClient = new DmaapHttpClientImpl(configuration).getHttpClient(); this.dmaapHostName = configuration.dmaapHostName(); this.dmaapProtocol = configuration.dmaapProtocol(); @@ -108,38 +108,31 @@ public class ExtendedDmaapConsumerHttpClientImpl { } private URI createDmaapConsumerExtendedURI() { - URI extendedURI = null; - - final URIBuilder uriBuilder = new URIBuilder() + try { + return new URIBuilder() .setScheme(dmaapProtocol) .setHost(dmaapHostName) .setPort(dmaapPortNumber) - .setPath(createRequestPath()); - - try { - extendedURI = uriBuilder.build(); - logger.info("Building extended URI: {}", extendedURI); + .setPath(createRequestPath()).build(); } catch (URISyntaxException e) { - logger.error("Exception while building extended URI: {}", e); + throw new RuntimeException("Exception while building extended URI: {}", e); } - - return extendedURI; } private ResponseHandler<Optional<String>> dmaapConsumerResponseHandler() { - return httpResponse -> { + return httpResponse -> { final int responseCode = httpResponse.getStatusLine().getStatusCode(); logger.info("Status code of operation: {}", responseCode); final HttpEntity responseEntity = httpResponse.getEntity(); - if (HttpUtils.isSuccessfulResponseCode(responseCode) ) { + if (HttpUtils.isSuccessfulResponseCode(responseCode)) { logger.info("HTTP response successful."); final String dmaapResponse = EntityUtils.toString(responseEntity); return Optional.of(dmaapResponse); } else { String dmaapResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : ""; logger.error("HTTP response not successful : {}", dmaapResponse); - return Optional.of("" + responseCode); + return Optional.of(String.valueOf(responseCode)); } }; } diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java index 6541fe96..a0877feb 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java @@ -28,11 +28,9 @@ import java.util.Optional; @Value.Style(builder = "new") public abstract class DmaapPublisherRequestDetails { - private static final long serialVersionUID = 1L; - @Value.Parameter public abstract String dmaapAPIPath(); @Value.Parameter - public abstract Optional<String> jsonBody(); + public abstract String jsonBody(); } diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java index 17e34ed0..af7534c6 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java @@ -52,7 +52,7 @@ public class ExtendedDmaapProducerHttpClientImpl { private final String dmaapContentType; - ExtendedDmaapProducerHttpClientImpl(DmaapPublisherConfiguration configuration) { + public ExtendedDmaapProducerHttpClientImpl(DmaapPublisherConfiguration configuration) { this.closeableHttpClient = new DmaapHttpClientImpl(configuration).getHttpClient(); this.dmaapHostName = configuration.dmaapHostName(); this.dmaapProtocol = configuration.dmaapProtocol(); @@ -61,7 +61,7 @@ public class ExtendedDmaapProducerHttpClientImpl { this.dmaapContentType = configuration.dmaapContentType(); } - Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) { + public Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) { Optional<String> extendedDetails = Optional.empty(); Optional<HttpRequestBase> request = createRequest(requestDetails); @@ -74,11 +74,7 @@ public class ExtendedDmaapProducerHttpClientImpl { return extendedDetails; } - - private Boolean isExtendedURINotNull(URI extendedURI) { - return extendedURI != null; - } - + private Optional<StringEntity> createStringEntity(Optional<String> jsonBody) { return Optional.of(parseJson(jsonBody).get()); } @@ -95,7 +91,7 @@ public class ExtendedDmaapProducerHttpClientImpl { return stringEntity; } - private Optional<HttpRequestBase> createRequest (DmaapPublisherRequestDetails requestDetails) { + private Optional<HttpRequestBase> createRequest(DmaapPublisherRequestDetails requestDetails) { Optional<HttpRequestBase> request = Optional.empty(); final URI extendedURI = createDmaapPublisherExtendedURI(requestDetails); @@ -112,24 +108,24 @@ public class ExtendedDmaapProducerHttpClientImpl { URI extendedURI = null; final URIBuilder uriBuilder = new URIBuilder() - .setScheme(dmaapProtocol) - .setHost(dmaapHostName) - .setPort(dmaapPortNumber) - .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName); + .setScheme(dmaapProtocol) + .setHost(dmaapHostName) + .setPort(dmaapPortNumber) + .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName); try { extendedURI = uriBuilder.build(); - logger.info("Building extended URI: {}",extendedURI); + logger.info("Building extended URI: {}", extendedURI); } catch (URISyntaxException e) { - logger.error("Exception while building extended URI: {}", e); + logger.error("Exception while building extended URI: ", e); } return extendedURI; } private HttpRequestBase createRequest(URI extendedURI, DmaapPublisherRequestDetails requestDetails) { - if (isExtendedURINotNull(extendedURI) && requestDetails.jsonBody().isPresent()) { - return createHttpPost(extendedURI, requestDetails.jsonBody()); + if (extendedURI != null) { + return createHttpPost(extendedURI, Optional.ofNullable(requestDetails.jsonBody())); } else { return null; } @@ -143,7 +139,7 @@ public class ExtendedDmaapProducerHttpClientImpl { } private ResponseHandler<Optional<String>> dmaapProducerResponseHandler() { - return httpResponse -> { + return httpResponse -> { final int responseCode = httpResponse.getStatusLine().getStatusCode(); final HttpEntity responseEntity = httpResponse.getEntity(); |