mirror of https://github.com/apache/nifi.git
NIFI-3614 Adding "return" statement to HandleHttpResponse when statusCode is not a number
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #1598.
This commit is contained in:
parent
d05727b8c0
commit
5daeba6e03
|
@ -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);
|
||||
|
|
|
@ -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<String, String> 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;
|
||||
|
|
Loading…
Reference in New Issue