From 2e1b87fa43e8af05ae9f08970b5d78c60e58c1c8 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Thu, 9 Feb 2017 20:10:33 +0100 Subject: [PATCH] NIFI-3403 - Fix NPE in InvokeHTTP Signed-off-by: Mike Moser This closes #1494 --- .../nifi/processors/standard/InvokeHTTP.java | 2 +- .../standard/util/TestInvokeHttpCommon.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java index c95b639433..66f7561683 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java @@ -863,7 +863,7 @@ public final class InvokeHTTP extends AbstractProcessor { // iterate through the flowfile attributes, adding any attribute that // matches the attributes-to-send pattern. if the pattern is not set // (it's an optional property), ignore that attribute entirely - if (regexAttributesToSend != null) { + if (regexAttributesToSend != null && requestFlowFile != null) { Map attributes = requestFlowFile.getAttributes(); Matcher m = regexAttributesToSend.matcher(""); for (Map.Entry entry : attributes.entrySet()) { diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestInvokeHttpCommon.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestInvokeHttpCommon.java index 5b6324304c..5b1e404b4d 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestInvokeHttpCommon.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestInvokeHttpCommon.java @@ -448,6 +448,35 @@ public abstract class TestInvokeHttpCommon { bundle1.assertAttributeEquals("Content-Type", "text/plain;charset=iso-8859-1"); } + @Test + public void testNoInputWithAttributes() throws Exception { + addHandler(new GetOrHeadHandler()); + + runner.setProperty(InvokeHTTP.PROP_URL, url + "/status/200"); + runner.setProperty(InvokeHTTP.PROP_METHOD, "GET"); + runner.setProperty(InvokeHTTP.PROP_ATTRIBUTES_TO_SEND, "myAttribute"); + runner.setIncomingConnection(false); + runner.setNonLoopConnection(false); + + runner.run(); + + runner.assertTransferCount(InvokeHTTP.REL_SUCCESS_REQ, 0); + runner.assertTransferCount(InvokeHTTP.REL_RESPONSE, 1); + runner.assertTransferCount(InvokeHTTP.REL_RETRY, 0); + runner.assertTransferCount(InvokeHTTP.REL_NO_RETRY, 0); + runner.assertTransferCount(InvokeHTTP.REL_FAILURE, 0); + runner.assertPenalizeCount(0); + + // expected in response + // status code, status message, all headers from server response --> ff attributes + // server response message body into payload of ff + final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(InvokeHTTP.REL_RESPONSE).get(0); + bundle1.assertContentEquals("/status/200".getBytes("UTF-8")); + bundle1.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200"); + bundle1.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK"); + bundle1.assertAttributeEquals("Content-Type", "text/plain;charset=iso-8859-1"); + } + @Test public void testNoInputFail() throws Exception { addHandler(new GetOrHeadHandler());