Skip to content

Commit

Permalink
NIFI-13372 Do not write exception details in FlowFile attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
EndzeitBegins committed Jul 10, 2024
1 parent e269a54 commit 59d258c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,8 @@
Using 'DeleteSFTP', delete the file residing on an SFTP server only after the result has been stored.
"""
)
@WritesAttributes({
@WritesAttribute(
attribute = DeleteSFTP.ATTRIBUTE_FAILURE_REASON,
description = "Human-readable reason of failure. Only available if FlowFile is routed to relationship 'failure'."),
@WritesAttribute(
attribute = DeleteSFTP.ATTRIBUTE_EXCEPTION_CLASS,
description = "The class name of the exception thrown during processor execution. Only available if an exception caused the FlowFile to be routed to relationship 'failure'."),
@WritesAttribute(
attribute = DeleteSFTP.ATTRIBUTE_EXCEPTION_MESSAGE,
description = "The message of the exception thrown during processor execution. Only available if an exception caused the FlowFile to be routed to relationship 'failure'.")
})
public class DeleteSFTP extends AbstractProcessor {

public static final String ATTRIBUTE_FAILURE_REASON = "DeleteSFTP.failure.reason";
public static final String ATTRIBUTE_EXCEPTION_CLASS = "DeleteSFTP.failure.exception.class";
public static final String ATTRIBUTE_EXCEPTION_MESSAGE = "DeleteSFTP.failure.exception.message";

public static final Relationship REL_SUCCESS = new Relationship.Builder()
.name("success")
.description("All FlowFiles, for which an existing file has been deleted, are routed to this relationship")
Expand Down Expand Up @@ -232,11 +217,6 @@ protected Collection<ValidationResult> customValidate(ValidationContext validati
private void handleFailure(ProcessSession session, FlowFile flowFile, String errorMessage, Throwable throwable) {
getLogger().error(errorMessage, throwable);

session.putAttribute(flowFile, ATTRIBUTE_FAILURE_REASON, errorMessage);
if (throwable != null) {
session.putAttribute(flowFile, ATTRIBUTE_EXCEPTION_CLASS, throwable.getClass().toString());
session.putAttribute(flowFile, ATTRIBUTE_EXCEPTION_MESSAGE, throwable.getMessage());
}
session.penalize(flowFile);
session.transfer(flowFile, REL_FAILURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ void sendsFlowFileToFailureWhenTargetIsADirectory() throws IOException {
assertExists(fileToDelete);
runner.assertAllFlowFilesTransferred(DeleteSFTP.REL_FAILURE);
runner.assertPenalizeCount(1);
final MockFlowFile resultFlowFile = runner.getFlowFilesForRelationship(DeleteSFTP.REL_FAILURE).getFirst();
resultFlowFile.assertAttributeExists(DeleteSFTP.ATTRIBUTE_FAILURE_REASON);
resultFlowFile.assertAttributeExists(DeleteSFTP.ATTRIBUTE_EXCEPTION_CLASS);
resultFlowFile.assertAttributeExists(DeleteSFTP.ATTRIBUTE_EXCEPTION_MESSAGE);
}

@Test
Expand All @@ -138,10 +134,6 @@ void sendsFlowFileToFailureWhenFileIsNotADirectChildOfTheDirectory() throws IOEx
assertExists(fileToDelete);
runner.assertAllFlowFilesTransferred(DeleteSFTP.REL_FAILURE, 1);
runner.assertPenalizeCount(1);
final MockFlowFile resultFlowFile = runner.getFlowFilesForRelationship(DeleteSFTP.REL_FAILURE).getFirst();
resultFlowFile.assertAttributeExists(DeleteSFTP.ATTRIBUTE_FAILURE_REASON);
resultFlowFile.assertAttributeNotExists(DeleteSFTP.ATTRIBUTE_EXCEPTION_CLASS);
resultFlowFile.assertAttributeNotExists(DeleteSFTP.ATTRIBUTE_EXCEPTION_MESSAGE);
}

@Test
Expand Down

0 comments on commit 59d258c

Please sign in to comment.