From 5daeba6e039d465b3ff19b5523b4c10d53475c83 Mon Sep 17 00:00:00 2001 From: Joe Percivall Date: Thu, 16 Mar 2017 14:11:46 -0400 Subject: [PATCH] NIFI-3614 Adding "return" statement to HandleHttpResponse when statusCode is not a number Signed-off-by: Pierre Villard This closes #1598. --- .../standard/HandleHttpResponse.java | 1 + .../standard/TestHandleHttpResponse.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpResponse.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpResponse.java index 2244ca6366..7fe0b71217 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpResponse.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpResponse.java @@ -136,6 +136,7 @@ public class HandleHttpResponse extends AbstractProcessor { if (!isNumber(statusCodeValue)) { session.transfer(flowFile, REL_FAILURE); getLogger().error("Failed to respond to HTTP request for {} because status code was '{}', which is not a valid number", new Object[]{flowFile, statusCodeValue}); + return; } final HttpContextMap contextMap = context.getProperty(HTTP_CONTEXT_MAP).asControllerService(HttpContextMap.class); diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java index ba402d4851..d9fc0b5ed4 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java @@ -142,6 +142,28 @@ public class TestHandleHttpResponse { assertEquals(1, contextMap.getCompletionCount()); } + @Test + public void testStatusCodeEmpty() throws InitializationException { + final TestRunner runner = TestRunners.newTestRunner(HandleHttpResponse.class); + + final MockHttpContextMap contextMap = new MockHttpContextMap("my-id", ""); + runner.addControllerService("http-context-map", contextMap); + runner.enableControllerService(contextMap); + runner.setProperty(HandleHttpResponse.HTTP_CONTEXT_MAP, "http-context-map"); + runner.setProperty(HandleHttpResponse.STATUS_CODE, "${status.code}"); + + final Map attributes = new HashMap<>(); + attributes.put(HTTPUtils.HTTP_CONTEXT_ID, "my-id"); + attributes.put("my-attr", "hello"); + + runner.enqueue("hello".getBytes(), attributes); + + runner.run(); + + runner.assertAllFlowFilesTransferred(HandleHttpResponse.REL_FAILURE, 1); + assertEquals(0, contextMap.getCompletionCount()); + } + private static class MockHttpContextMap extends AbstractControllerService implements HttpContextMap { private final String id;