markap14 commented on a change in pull request #3559: NIFI-1624 Allow 
ExtractText processor to fail if max. capture group l…
URL: https://github.com/apache/nifi/pull/3559#discussion_r314056771
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractText.java
 ##########
 @@ -372,7 +411,23 @@ public void process(InputStream in) throws IOException {
                     String value = matcher.group(i);
                     if (value != null && !value.isEmpty()) {
                         if (value.length() > maxCaptureGroupLength) {
-                            value = value.substring(0, maxCaptureGroupLength);
+                            if (logger.isDebugEnabled()) {
+                                
logger.debug(String.format(errorMessageOnCaptureGroupLengthExcess, value, 
maxCaptureGroupLength, flowFile));
+                            }
+                            switch (excessPolicy) {
+                                case TRUNCATE:
+                                    value = value.substring(0, 
maxCaptureGroupLength);
+                                    break;
+                                case FAIL:
+                                    final String errorMsg = 
String.format(errorMessageOnCaptureGroupLengthExcess,
+                                            value, maxCaptureGroupLength, 
flowFile);
+                                    flowFile = session.putAttribute(flowFile, 
ERROR_MSG_KEY, errorMsg);
+                                    
session.getProvenanceReporter().modifyAttributes(flowFile);
+                                    session.transfer(flowFile, FAILURE);
+                                    logger.info("Transferred FlowFile {} to 
FAILURE relationship due to excess of capture group maximum length.",
 
 Review comment:
   Would avoid capitalizing FAILURE here since the relationship name is failure 
in lowercase.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to