summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main/java
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-06-11 14:16:09 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-06-12 08:21:22 +0200
commitdabda661a59fb07c640bfe96bfc4675e3b10f04f (patch)
treee40a61f03eec149a3726163a9073fcc7549380f2 /prh-app-server/src/main/java
parent07ebdbb579bc2b9ef1f0e26d0c98d2c0fdcd353d (diff)
Catch empty response from DmaaP
Change-Id: Ibd8739c3f9718eec15ff20e0b88d0bfcd4f6d84d Issue-ID: DCAEGEN2-540 Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server/src/main/java')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java11
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java4
2 files changed, 9 insertions, 6 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
index 3bac7c36..ab4ec633 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
@@ -40,14 +40,15 @@ public class DmaapConsumerJsonParser {
private static final String PNF_VENDOR_NAME = "pnfVendorName";
private static final String PNF_SERIAL_NUMBER = "pnfSerialNumber";
- public ConsumerDmaapModel getJsonObject(String message) throws DmaapNotFoundException {
+ public Optional<ConsumerDmaapModel> getJsonObject(String message) throws DmaapNotFoundException {
JsonElement jsonElement = new JsonParser().parse(message);
if (jsonElement.isJsonObject()) {
- return create(jsonElement.getAsJsonObject());
+ return Optional.of(create(jsonElement.getAsJsonObject()));
} else {
- return create(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
- .flatMap(this::getJsonObjectFromAnArray)
- .orElseThrow(() -> new DmaapNotFoundException("Json object not found in json array")));
+ return Optional
+ .of(create(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false).findFirst()
+ .flatMap(this::getJsonObjectFromAnArray)
+ .orElse(null)));
}
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
index 01b85a9d..9d818366 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
@@ -60,7 +60,9 @@ public class DmaapConsumerTaskImpl extends
@Override
ConsumerDmaapModel consume(String message) throws DmaapNotFoundException {
logger.trace("Method called with arg {}", message);
- return dmaapConsumerJsonParser.getJsonObject(message);
+ return dmaapConsumerJsonParser.getJsonObject(message)
+ .orElseThrow(() -> new DmaapNotFoundException(String.format("Nothing to consume from DmaaP %s topic.",
+ resolveConfiguration().dmaapTopicName())));
}
@Override