From a393ae34963a919b842127cc8943a94f2d7c1bc7 Mon Sep 17 00:00:00 2001 From: pwielebs Date: Mon, 7 May 2018 16:58:20 +0200 Subject: AAI client configuration & tasks changed Change-Id: I86a2f2ed62565263f2be2c9078a092f993234a19 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs --- .../producer/DmaapPublisherRequestDetails.java | 36 ---------------------- .../ExtendedDmaapProducerHttpClientImpl.java | 29 +++++++---------- 2 files changed, 11 insertions(+), 54 deletions(-) delete mode 100644 prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java (limited to 'prh-dmaap-client/src/main/java/org') 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 deleted file mode 100644 index a0877feb..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.service.producer; - -import org.immutables.value.Value; - -import java.util.Optional; - -@Value.Immutable(prehash = true) -@Value.Style(builder = "new") -public abstract class DmaapPublisherRequestDetails { - - @Value.Parameter - public abstract String dmaapAPIPath(); - - @Value.Parameter - 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 98c9a83e..def9dd85 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 @@ -29,6 +29,8 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.model.CommonFunctions; +import org.onap.dcaegen2.services.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.service.DmaapHttpClientImpl; import org.onap.dcaegen2.services.service.HttpUtils; import org.slf4j.Logger; @@ -61,17 +63,14 @@ public class ExtendedDmaapProducerHttpClientImpl { this.dmaapContentType = configuration.dmaapContentType(); } - public Optional getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) { - + public Optional getHttpProducerResponse(ConsumerDmaapModel consumerDmaapModel) { Optional extendedDetails = Optional.empty(); - Optional request = createRequest(requestDetails); - + Optional request = createRequest(consumerDmaapModel); try { extendedDetails = closeableHttpClient.execute(request.get(), dmaapProducerResponseHandler()); } catch (IOException | NullPointerException e) { logger.warn("Exception while executing HTTP request: ", e); } - return extendedDetails; } @@ -81,51 +80,45 @@ public class ExtendedDmaapProducerHttpClientImpl { private Optional parseJson(Optional jsonBody) { Optional stringEntity = Optional.empty(); - try { stringEntity = Optional.of(new StringEntity(jsonBody.get())); } catch (UnsupportedEncodingException e) { logger.warn("Exception while parsing JSON: ", e); } - return stringEntity; } - private Optional createRequest(DmaapPublisherRequestDetails requestDetails) { - + private Optional createRequest(ConsumerDmaapModel consumerDmaapModel) { Optional request = Optional.empty(); - final URI extendedURI = createDmaapPublisherExtendedURI(requestDetails); + final URI extendedURI = createDmaapPublisherExtendedURI(); if ("application/json".equals(dmaapContentType)) { - request = Optional.ofNullable(createRequest(extendedURI, requestDetails)); + request = Optional.ofNullable(createRequest(extendedURI, consumerDmaapModel)); request.get().addHeader("Content-type", dmaapContentType); } return request; } - private URI createDmaapPublisherExtendedURI(DmaapPublisherRequestDetails requestDetails) { + private URI createDmaapPublisherExtendedURI() { URI extendedURI = null; - final URIBuilder uriBuilder = new URIBuilder() .setScheme(dmaapProtocol) .setHost(dmaapHostName) .setPort(dmaapPortNumber) - .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName); - + .setPath(dmaapTopicName); try { extendedURI = uriBuilder.build(); logger.trace("Building extended URI: {}", extendedURI); } catch (URISyntaxException e) { logger.warn("Exception while building extended URI: ", e); } - return extendedURI; } - private HttpRequestBase createRequest(URI extendedURI, DmaapPublisherRequestDetails requestDetails) { + private HttpRequestBase createRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) { if (extendedURI != null) { - return createHttpPost(extendedURI, Optional.ofNullable(requestDetails.jsonBody())); + return createHttpPost(extendedURI, Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel))); } else { return null; } -- cgit 1.2.3-korg