mirror of https://github.com/apache/nifi.git
NIFI-374: Route ProcessException's to failure
This commit is contained in:
parent
6e5469c712
commit
ab6794b29e
|
@ -172,7 +172,9 @@ public class EncryptContent extends AbstractProcessor {
|
|||
final int saltSize = (algorithmBlockSize > 0) ? algorithmBlockSize : DEFAULT_SALT_SIZE;
|
||||
|
||||
final StopWatch stopWatch = new StopWatch(true);
|
||||
if (context.getProperty(MODE).getValue().equalsIgnoreCase(ENCRYPT_MODE)) {
|
||||
final String mode = context.getProperty(MODE).getValue();
|
||||
try {
|
||||
if (mode.equalsIgnoreCase(ENCRYPT_MODE)) {
|
||||
final byte[] salt = new byte[saltSize];
|
||||
secureRandom.nextBytes(salt);
|
||||
|
||||
|
@ -200,6 +202,10 @@ public class EncryptContent extends AbstractProcessor {
|
|||
|
||||
session.getProvenanceReporter().modifyContent(flowFile, stopWatch.getElapsed(TimeUnit.MILLISECONDS));
|
||||
session.transfer(flowFile, REL_SUCCESS);
|
||||
} catch (final ProcessException pe) {
|
||||
getLogger().error("Failed to {} {} due to {}; routing to failure", new Object[] {mode, flowFile, pe});
|
||||
session.transfer(flowFile, REL_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DecryptCallback implements StreamCallback {
|
||||
|
|
|
@ -61,4 +61,25 @@ public class TestEncryptContent {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptNonEncryptedFile() throws IOException {
|
||||
final TestRunner testRunner = TestRunners.newTestRunner(new EncryptContent());
|
||||
testRunner.setProperty(EncryptContent.PASSWORD, "Hello, World!");
|
||||
|
||||
for (final EncryptionMethod method : EncryptionMethod.values()) {
|
||||
if (method.isUnlimitedStrength()) {
|
||||
continue; // cannot test unlimited strength in unit tests because it's not enabled by the JVM by default.
|
||||
}
|
||||
|
||||
testRunner.setProperty(EncryptContent.ENCRYPTION_ALGORITHM, method.name());
|
||||
testRunner.setProperty(EncryptContent.MODE, EncryptContent.DECRYPT_MODE);
|
||||
|
||||
testRunner.enqueue(Paths.get("src/test/resources/hello.txt"));
|
||||
testRunner.clearTransferState();
|
||||
testRunner.run();
|
||||
|
||||
testRunner.assertAllFlowFilesTransferred(EncryptContent.REL_FAILURE, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue