summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJoeOLeary <joseph.o.leary@est.tech>2019-02-18 15:13:16 +0000
committerJoeOLeary <joseph.o.leary@est.tech>2019-02-18 15:13:16 +0000
commit8e2c338d0195f31269811ba4ff3f1214a60907d1 (patch)
treef843bbbe774abba173db03b6342dead635ae7268 /src/main
parent32ba8905197d61b6a9610d50a57cf4ba31e53a52 (diff)
Fix DataRouter Subscriber NPE on No Metadata
Issue-ID: DCAEGEN2-1232 Change-Id: I692d65c460f2974535d5b9addc4d889c530cf951 Signed-off-by: JoeOLeary <joseph.o.leary@est.tech>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriber.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriber.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriber.java
index fc623bd..40efde5 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriber.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriber.java
@@ -155,6 +155,14 @@ public class DataRouterSubscriber implements HttpHandler {
}
}
+ private EventMetadata getMetadata(HttpServerExchange httpServerExchange) throws NoMetadataException {
+ String metadata = Optional.ofNullable(httpServerExchange.getRequestHeaders()
+ .get(METADATA_HEADER))
+ .map((HeaderValues headerValues) -> headerValues.get(0))
+ .orElseThrow(() -> new NoMetadataException("Metadata Not found"));
+ return metadataBuilder.fromJson(metadata, EventMetadata.class);
+ }
+
/**
* Receives inbound requests, verifies that required headers are valid
* and passes an Event onto the eventReceiver.
@@ -172,16 +180,13 @@ public class DataRouterSubscriber implements HttpHandler {
.send(StatusCodes.SERVICE_UNAVAILABLE_STRING);
} else {
try {
- String metadataAsString = Optional.of(httpServerExchange.getRequestHeaders()
- .get(METADATA_HEADER))
- .map((HeaderValues headerValues) -> headerValues.get(0))
- .orElseThrow(() -> new NoMetadataException("Metadata Not found"));
+
Map<String,String> mdc = MDC.getCopyOfContextMap();
- EventMetadata metadata = metadataBuilder.fromJson(metadataAsString, EventMetadata.class);
+ EventMetadata metadata = getMetadata(httpServerExchange);
httpServerExchange.getRequestReceiver()
- .receiveFullString((callbackExchange, body) -> {
- httpServerExchange.dispatch(() -> eventReceiver.receive(new Event(callbackExchange, body, metadata, mdc)));
- });
+ .receiveFullString((callbackExchange, body) ->
+ httpServerExchange.dispatch(() -> eventReceiver.receive(new Event(callbackExchange, body, metadata, mdc)))
+ );
} catch (NoMetadataException exception) {
logger.unwrap().info("Bad Request: no metadata found under '{}' header.", METADATA_HEADER, exception);
httpServerExchange.setStatusCode(StatusCodes.BAD_REQUEST)