summaryrefslogtreecommitdiffstats
path: root/prh-dmaap-client/src
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-04-24 10:07:41 +0200
committerpwielebs <piotr.wielebski@nokia.com>2018-04-24 10:09:36 +0200
commit74c5bf5b2f99043a8cb29aa8f2b9fde253b92e72 (patch)
tree1ddeb70f2943086c1196317ccf5dfc43cf301470 /prh-dmaap-client/src
parenta274374b520aad75c99cdce7f4f9ebc31ce74343 (diff)
Http clients refactoring
Change-Id: Ibed4b83fd508dd8666b76bdf590069d40dd3a363 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src')
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumer.java33
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerFactory.java30
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/consumer/DMaaPConsumerImpl.java68
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/DmaapHttpClientImpl.java1
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java12
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java14
6 files changed, 8 insertions, 150 deletions
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 <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
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 <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
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 <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 {
-
- }
-}
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<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;
}
-
-
}