From 74c5bf5b2f99043a8cb29aa8f2b9fde253b92e72 Mon Sep 17 00:00:00 2001 From: pwielebs Date: Tue, 24 Apr 2018 10:07:41 +0200 Subject: Http clients refactoring Change-Id: Ibed4b83fd508dd8666b76bdf590069d40dd3a363 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs --- .../service/AAIExtendedHttpClientImpl.java | 29 +++++---- .../dcaegen2/services/consumer/DMaaPConsumer.java | 33 ----------- .../services/consumer/DMaaPConsumerFactory.java | 30 ---------- .../services/consumer/DMaaPConsumerImpl.java | 68 ---------------------- .../services/service/DmaapHttpClientImpl.java | 1 - .../ExtendedDmaapConsumerHttpClientImpl.java | 12 ++-- .../ExtendedDmaapProducerHttpClientImpl.java | 14 ++--- 7 files changed, 21 insertions(+), 166 deletions(-) delete mode 100644 prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumer.java delete mode 100644 prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerFactory.java delete mode 100644 prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerImpl.java diff --git a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImpl.java b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImpl.java index 2e6aa9e6..20ae8d0b 100644 --- a/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImpl.java +++ b/prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImpl.java @@ -19,13 +19,6 @@ */ package org.onap.dcaegen2.services.service; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.client.ResponseHandler; @@ -43,9 +36,16 @@ import org.onap.dcaegen2.services.utils.HttpUtils; import org.onap.dcaegen2.services.utils.RequestVerbs; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.lang.NonNull; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Iterator; +import java.util.Map; +import java.util.Optional; + public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient { Logger logger = LoggerFactory.getLogger(AAIExtendedHttpClientImpl.class); @@ -55,7 +55,7 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient { private final String aaiProtocol; private final Integer aaiHostPortNumber; - @Autowired + public AAIExtendedHttpClientImpl (AAIHttpClientConfiguration aaiHttpClientConfiguration) { final AAIHttpClient aaiHttpClient = new AAIHttpClientImpl(aaiHttpClientConfiguration); closeableHttpClient = aaiHttpClient.getAAIHttpClient(); @@ -76,14 +76,11 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient { logger.error("Exception while executing HTTP request: {}", e); } - if (extendedDetails.isPresent()) { - return extendedDetails; - } else { - return Optional.empty(); - } + return extendedDetails; } private URI createAAIExtendedURI(final String path, Map queryParams) { + URI extendedURI = null; final URIBuilder uriBuilder = new URIBuilder().setScheme(this.aaiProtocol).setHost(this.aaiHost) @@ -96,8 +93,8 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient { } try { - logger.info("Building extended URI"); extendedURI = uriBuilder.build(); + logger.info("Building extended URI: {}", extendedURI); } catch (URISyntaxException e) { logger.error("Exception while building extended URI: {}", e); } @@ -151,7 +148,7 @@ public class AAIExtendedHttpClientImpl implements AAIExtendedHttpClient { } private Boolean isExtendedURINotNull(URI extendedURI) { - return extendedURI != null ? true : false; + return extendedURI != null; } private Optional createStringEntity(Optional jsonBody) { diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumer.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumer.java deleted file mode 100644 index 5e9705ae..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumer.java +++ /dev/null @@ -1,33 +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.consumer; - -import java.util.Date; -import org.onap.dcaegen2.services.response.DMaaPConsumerResponse; - -/** - * @author Przemysław Wąsala on 4/17/18 - */ -public interface DMaaPConsumer extends AutoCloseable { - - DMaaPConsumerResponse fetchMessages(); - - Date getSubscriberCreationTime(); -} diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerFactory.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerFactory.java deleted file mode 100644 index 4864d679..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerFactory.java +++ /dev/null @@ -1,30 +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.consumer; - -import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; - -/** - * @author Przemysław Wąsala on 4/17/18 - */ -public interface DMaaPConsumerFactory { - - DMaaPConsumer create(DmaapConsumerConfiguration dmaapConsumerConfiguration); -} diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerImpl.java deleted file mode 100644 index e9511ce3..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerImpl.java +++ /dev/null @@ -1,68 +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.consumer; - -import java.net.URI; -import java.time.Instant; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import org.apache.http.impl.client.CloseableHttpClient; -import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; -import org.onap.dcaegen2.services.response.DMaaPConsumerResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Przemysław Wąsala on 4/17/18 - */ -public class DMaaPConsumerImpl implements DMaaPConsumer { - - private static final Logger logger = LoggerFactory.getLogger(DMaaPConsumerImpl.class); - private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - - private final DmaapConsumerConfiguration dmaapConsumerConfiguration; - private final CloseableHttpClient closeableHttpClient; - private final URI subscriberUri; - private final Date subscriberCreationTime; - - public DMaaPConsumerImpl(DmaapConsumerConfiguration dmaapConsumerConfiguration, - CloseableHttpClient closeableHttpClient, URI subscriberUri) { - this.dmaapConsumerConfiguration = dmaapConsumerConfiguration; - this.closeableHttpClient = closeableHttpClient; - this.subscriberUri = subscriberUri; - this.subscriberCreationTime = Date.from(Instant.from(LocalTime.now())); - } - - @Override - public DMaaPConsumerResponse fetchMessages() { - return null; - } - - @Override - public Date getSubscriberCreationTime() { - return null; - } - - @Override - public void close() throws Exception { - - } -} diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/DmaapHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/DmaapHttpClientImpl.java index be4442d7..f2917d02 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/DmaapHttpClientImpl.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/DmaapHttpClientImpl.java @@ -67,5 +67,4 @@ public class DmaapHttpClientImpl { return httpClientBuilder.build(); } - } 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 30d7ad86..5acf2042 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 @@ -50,7 +50,7 @@ public class ExtendedDmaapConsumerHttpClientImpl { private final String dmaapContentType; - public ExtendedDmaapConsumerHttpClientImpl(DmaapConsumerConfiguration configuration) { + ExtendedDmaapConsumerHttpClientImpl(DmaapConsumerConfiguration configuration) { this.closeableHttpClient = new DmaapHttpClientImpl(configuration).getHttpClient(); this.dmaapHostName = configuration.dmaapHostName(); this.dmaapProtocol = configuration.dmaapProtocol(); @@ -72,11 +72,7 @@ public class ExtendedDmaapConsumerHttpClientImpl { logger.error("Exception while executing HTTP request: {}", e); } - if (extendedDetails.isPresent()) { - return extendedDetails; - } else { - return Optional.empty(); - } + return extendedDetails; } private static HttpRequestBase createHttpRequest(URI extendedURI) { @@ -97,7 +93,7 @@ public class ExtendedDmaapConsumerHttpClientImpl { final URI extendedURI = createDmaapConsumerExtendedURI(); if ("application/json".equals(dmaapContentType)) { - request = Optional.of(createHttpRequest(extendedURI)); + request = Optional.ofNullable(createHttpRequest(extendedURI)); request.get().addHeader("Content-type", dmaapContentType); } @@ -118,8 +114,8 @@ public class ExtendedDmaapConsumerHttpClientImpl { .setPath(createRequestPath()); try { - logger.info("Building extended URI"); extendedURI = uriBuilder.build(); + logger.info("Building extended URI: {}", extendedURI); } catch (URISyntaxException e) { logger.error("Exception while building extended URI: {}", e); } 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 32972273..9b6c96ff 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 @@ -58,7 +58,7 @@ public class ExtendedDmaapProducerHttpClientImpl { this.dmaapContentType = configuration.dmaapContentType(); } - public Optional getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) { + Optional getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) { Optional extendedDetails = Optional.empty(); Optional request = createRequest(requestDetails); @@ -69,11 +69,7 @@ public class ExtendedDmaapProducerHttpClientImpl { logger.error("Exception while executing HTTP request: {}", e); } - if (extendedDetails.isPresent()) { - return extendedDetails; - } else { - return Optional.empty(); - } + return extendedDetails; } private Boolean isExtendedURINotNull(URI extendedURI) { @@ -102,7 +98,7 @@ public class ExtendedDmaapProducerHttpClientImpl { final URI extendedURI = createDmaapPublisherExtendedURI(requestDetails); if ("application/json".equals(dmaapContentType)) { - request = Optional.of(createRequest(extendedURI, requestDetails)); + request = Optional.ofNullable(createRequest(extendedURI, requestDetails)); request.get().addHeader("Content-type", dmaapContentType); } @@ -119,8 +115,8 @@ public class ExtendedDmaapProducerHttpClientImpl { .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName); try { - logger.info("Building extended URI"); extendedURI = uriBuilder.build(); + logger.info("Building extended URI: {}",extendedURI); } catch (URISyntaxException e) { logger.error("Exception while building extended URI: {}", e); } @@ -142,6 +138,4 @@ public class ExtendedDmaapProducerHttpClientImpl { post.setEntity(stringEntity.get()); return post; } - - } -- cgit 1.2.3-korg