NIFI-3403 - Fix NPE in InvokeHTTP

Signed-off-by: Mike Moser <mosermw@apache.org>

This closes #1494
This commit is contained in:
Pierre Villard 2017-02-09 20:10:33 +01:00 committed by Mike Moser
parent 4e4d14f86f
commit 2e1b87fa43
2 changed files with 30 additions and 1 deletions

View File

@ -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<String, String> attributes = requestFlowFile.getAttributes();
Matcher m = regexAttributesToSend.matcher("");
for (Map.Entry<String, String> entry : attributes.entrySet()) {

View File

@ -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());