This is an automated email from the ASF dual-hosted git repository.
mthomsen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/master by this push:
new cfcf2e6 NIFI-6682 SplitJson does not work if the input is null
cfcf2e6 is described below
commit cfcf2e698df34eb097c23a404c1a346a4aeb9c60
Author: Otto Fowler <[email protected]>
AuthorDate: Thu Sep 26 17:54:06 2019 -0400
NIFI-6682 SplitJson does not work if the input is null
This closes #3772
Signed-off-by: Mike Thomsen <[email protected]>
---
.../standard/AbstractJsonPathProcessor.java | 11 +++++++++++
.../nifi/processors/standard/TestSplitJson.java | 19 +++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java
index faac0a9..81c7aa8 100644
---
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java
+++
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractJsonPathProcessor.java
@@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
@@ -79,6 +80,16 @@ public abstract class AbstractJsonPathProcessor extends
AbstractProcessor {
try (BufferedInputStream bufferedInputStream = new
BufferedInputStream(in)) {
DocumentContext ctx =
JsonPath.using(STRICT_PROVIDER_CONFIGURATION).parse(bufferedInputStream);
contextHolder.set(ctx);
+ } catch (IllegalArgumentException iae) {
+ // The JsonPath.parse() above first parses the json, then
creates a context object from the parsed
+ // json. It is possible for the json parsing to complete
without error, but produce a null object.
+ // In this case the context creation will fail and throw
an IllegalArgumentException. This is in
+ // my opinion a bug in the JsonPath library, as it doesn't
really throw the correct exception
+ // contextually.
+ // The general handling in derived classes handles
InvalidJsonException.
+ // The best thing to do here, is to re-throw with the
proper exception, such that the calling logic
+ // can route.
+ throw new InvalidJsonException(iae);
}
}
});
diff --git
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
index c255249..c4627b2 100644
---
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
+++
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
@@ -235,4 +235,23 @@ public class TestSplitJson {
testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(i).assertContentEquals("null");
}
}
+
+ @Test
+ public void testSplit_pathToInputStringNullValue() throws Exception {
+ final TestRunner testRunner = TestRunners.newTestRunner(new
SplitJson());
+ testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.*");
+ ProcessSession session =
testRunner.getProcessSessionFactory().createSession();
+ FlowFile ff = session.create();
+ ff = session.write(ff, new OutputStreamCallback() {
+ @Override
+ public void process(OutputStream out) throws IOException {
+ try (OutputStream outputStream = new
BufferedOutputStream(out)) {
+
outputStream.write("null".getBytes(StandardCharsets.UTF_8));
+ }
+ }
+ });
+ testRunner.enqueue(ff);
+ testRunner.run();
+ testRunner.assertTransferCount(SplitJson.REL_FAILURE, 1);
+ }
}