You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jp...@apache.org on 2016/05/06 22:47:59 UTC
nifi git commit: NIFI-1814 Extended caught exceptions
Repository: nifi
Updated Branches:
refs/heads/0.x 014a28b74 -> 3e718262a
NIFI-1814 Extended caught exceptions
This closes #382
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/3e718262
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/3e718262
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/3e718262
Branch: refs/heads/0.x
Commit: 3e718262a6f602a1dfc672bb44759e7f510f1767
Parents: 014a28b
Author: Pierre Villard <pi...@gmail.com>
Authored: Tue Apr 26 22:03:59 2016 +0200
Committer: jpercivall <jo...@yahoo.com>
Committed: Fri May 6 18:31:12 2016 -0400
----------------------------------------------------------------------
.../processors/standard/HandleHttpResponse.java | 5 +-
.../standard/TestHandleHttpResponse.java | 77 ++++++++++++++------
2 files changed, 56 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/3e718262/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpResponse.java
----------------------------------------------------------------------
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 ecc05ee..1a24e6e 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
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -155,9 +154,9 @@ public class HandleHttpResponse extends AbstractProcessor {
try {
session.exportTo(flowFile, response.getOutputStream());
response.flushBuffer();
- } catch (final IOException ioe) {
+ } catch (final Exception e) {
session.transfer(flowFile, REL_FAILURE);
- getLogger().error("Failed to respond to HTTP request for {} due to {}", new Object[]{flowFile, ioe});
+ getLogger().error("Failed to respond to HTTP request for {} due to {}", new Object[]{flowFile, e});
return;
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/3e718262/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java
----------------------------------------------------------------------
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 9e31a4e..84fb26d 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
@@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.http.HttpContextMap;
+import org.apache.nifi.processor.exception.FlowFileAccessException;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
@@ -53,7 +54,7 @@ public class TestHandleHttpResponse {
public void testEnsureCompleted() throws InitializationException {
final TestRunner runner = TestRunners.newTestRunner(HandleHttpResponse.class);
- final MockHttpContextMap contextMap = new MockHttpContextMap("my-id");
+ final MockHttpContextMap contextMap = new MockHttpContextMap("my-id", false);
runner.addControllerService("http-context-map", contextMap);
runner.enableControllerService(contextMap);
runner.setProperty(HandleHttpResponse.HTTP_CONTEXT_MAP, "http-context-map");
@@ -80,18 +81,44 @@ public class TestHandleHttpResponse {
assertTrue(contextMap.headersWithNoValue.isEmpty());
}
+ @Test
+ public void testWithExceptionThrown() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(HandleHttpResponse.class);
+
+ final MockHttpContextMap contextMap = new MockHttpContextMap("my-id", true);
+ 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}");
+ runner.setProperty("my-attr", "${my-attr}");
+ runner.setProperty("no-valid-attr", "${no-valid-attr}");
+
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put(HandleHttpResponse.HTTP_CONTEXT_ID, "my-id");
+ attributes.put("my-attr", "hello");
+ attributes.put("status.code", "201");
+
+ runner.enqueue("hello".getBytes(), attributes);
+
+ runner.run();
+
+ runner.assertAllFlowFilesTransferred(HandleHttpResponse.REL_FAILURE, 1);
+ }
+
private static class MockHttpContextMap extends AbstractControllerService implements HttpContextMap {
private final String id;
private final AtomicInteger completedCount = new AtomicInteger(0);
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
private final ConcurrentMap<String, String> headersSent = new ConcurrentHashMap<>();
+ private final boolean shouldThrowException;
private volatile int statusCode = -1;
private final List<String> headersWithNoValue = new CopyOnWriteArrayList<>();
- public MockHttpContextMap(final String expectedIdentifier) {
+ public MockHttpContextMap(final String expectedIdentifier, final boolean shouldThrowException) {
this.id = expectedIdentifier;
+ this.shouldThrowException = shouldThrowException;
}
@Override
@@ -107,31 +134,35 @@ public class TestHandleHttpResponse {
try {
final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
- Mockito.when(response.getOutputStream()).thenReturn(new ServletOutputStream() {
- @Override
- public boolean isReady() {
- return true;
- }
+ if(shouldThrowException) {
+ Mockito.when(response.getOutputStream()).thenThrow(new FlowFileAccessException("exception"));
+ } else {
+ Mockito.when(response.getOutputStream()).thenReturn(new ServletOutputStream() {
+ @Override
+ public boolean isReady() {
+ return true;
+ }
- @Override
- public void setWriteListener(WriteListener writeListener) {
- }
+ @Override
+ public void setWriteListener(WriteListener writeListener) {
+ }
- @Override
- public void write(int b) throws IOException {
- baos.write(b);
- }
+ @Override
+ public void write(int b) throws IOException {
+ baos.write(b);
+ }
- @Override
- public void write(byte[] b) throws IOException {
- baos.write(b);
- }
+ @Override
+ public void write(byte[] b) throws IOException {
+ baos.write(b);
+ }
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- baos.write(b, off, len);
- }
- });
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ baos.write(b, off, len);
+ }
+ });
+ }
Mockito.doAnswer(new Answer<Object>() {
@Override