diff options
author | Tony Hansen <tony@att.com> | 2019-02-19 17:08:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-19 17:08:45 +0000 |
commit | 7f82227820362daa3050a04620ca77faa5c52c1a (patch) | |
tree | b381e29bfe9c3d7d8d8a79f0edde9a7c38b25561 /src/main/java/org/onap | |
parent | 4d4dc481af71692a15dc66e0504ed7e8dcbe94af (diff) | |
parent | 8e2c338d0195f31269811ba4ff3f1214a60907d1 (diff) |
Merge "Fix DataRouter Subscriber NPE on No Metadata"
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r-- | src/main/java/org/onap/dcaegen2/services/pmmapper/datarouter/DataRouterSubscriber.java | 21 |
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) |