Http clients refactoring 03/44303/1
authorpwielebs <piotr.wielebski@nokia.com>
Tue, 24 Apr 2018 08:07:41 +0000 (10:07 +0200)
committerpwielebs <piotr.wielebski@nokia.com>
Tue, 24 Apr 2018 08:09:36 +0000 (10:09 +0200)
Change-Id: Ibed4b83fd508dd8666b76bdf590069d40dd3a363
Issue-ID: DCAEGEN2-451
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
prh-aai-client/src/main/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImpl.java
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumer.java [deleted file]
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerFactory.java [deleted file]
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerImpl.java [deleted file]
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/DmaapHttpClientImpl.java
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java
prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java

index 2e6aa9e..20ae8d0 100644 (file)
  */
 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<String, String> 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<StringEntity> createStringEntity(Optional<String> 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 (file)
index 5e9705a..0000000
+++ /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 <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> 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 (file)
index 4864d67..0000000
+++ /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 <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> 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 (file)
index e9511ce..0000000
+++ /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 <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> 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 {
-
-    }
-}
index 30d7ad8..5acf204 100644 (file)
@@ -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);
         }
index 3297227..9b6c96f 100644 (file)
@@ -58,7 +58,7 @@ public class ExtendedDmaapProducerHttpClientImpl {
         this.dmaapContentType = configuration.dmaapContentType();
     }
 
-    public Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) {
+     Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) {
 
         Optional<String> extendedDetails = Optional.empty();
         Optional<HttpRequestBase> 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;
     }
-
-
 }