This is an automated email from the ASF dual-hosted git repository.
otto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 74b25c7306 NIFI-10154 ReplaceText AdminYielding on long line (#6151)
74b25c7306 is described below
commit 74b25c73069350354acc875420e834605e1a8bef
Author: NissimShiman <[email protected]>
AuthorDate: Fri Jul 22 11:14:23 2022 -0400
NIFI-10154 ReplaceText AdminYielding on long line (#6151)
* NIFI-10154 ReplaceText AdminYielding on long line
* NIFI-10154 code review changes
Signed-off-by: Otto Fowler <[email protected]>
---
.../nifi/stream/io/util/AbstractTextDemarcator.java | 4 +---
.../apache/nifi/processors/standard/ReplaceText.java | 7 ++++++-
.../nifi/processors/standard/TestReplaceText.java | 17 +++++++++++++++++
.../apacheLicenseOnOneLine.txt | 1 +
4 files changed, 25 insertions(+), 4 deletions(-)
diff --git
a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/AbstractTextDemarcator.java
b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/AbstractTextDemarcator.java
index f10f66df3c..048798161e 100644
---
a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/AbstractTextDemarcator.java
+++
b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/AbstractTextDemarcator.java
@@ -16,8 +16,6 @@
*/
package org.apache.nifi.stream.io.util;
-import org.apache.nifi.stream.io.exception.TokenTooLargeException;
-
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@@ -94,7 +92,7 @@ public abstract class AbstractTextDemarcator implements
Closeable {
/**
* Will fill the current buffer from current 'index' position, expanding it
* and or shuffling it if necessary. If buffer exceeds max buffer size a
- * {@link TokenTooLargeException} will be thrown.
+ * {@link BufferOverflowException} will be thrown.
*
* @throws IOException
* if unable to read from the stream
diff --git
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
index 7d5eae4d84..2b1effbc73 100644
---
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
+++
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
@@ -58,6 +58,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.nio.BufferOverflowException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
@@ -315,7 +316,7 @@ public class ReplaceText extends AbstractProcessor {
if (evaluateMode.equalsIgnoreCase(ENTIRE_TEXT)) {
if (flowFile.getSize() > maxBufferSize &&
replacementStrategyExecutor.isAllDataBufferedForEntireText()) {
- logger.warn("Transferred {} to 'faliure' because it was larger
than the buffer size");
+ logger.warn("Transferred {} to 'failure' because it was larger
than the buffer size");
session.transfer(flowFile, REL_FAILURE);
return;
}
@@ -331,6 +332,10 @@ public class ReplaceText extends AbstractProcessor {
logger.info("Transferred {} to 'failure' due to {}", new Object[]
{ flowFile, e.toString() });
session.transfer(flowFile, REL_FAILURE);
return;
+ } catch (BufferOverflowException e) {
+ logger.warn("Transferred {} to 'failure' due to {}", new Object[]
{ flowFile, e.toString()});
+ session.transfer(flowFile, REL_FAILURE);
+ return;
} catch (IllegalAttributeException |
AttributeExpressionLanguageException e) {
logger.warn("Transferred {} to 'failure' due to {}", new Object[]
{ flowFile, e.toString() }, e);
session.transfer(flowFile, REL_FAILURE);
diff --git
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
index 88ed09747e..ad92319865 100644
---
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
+++
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
@@ -781,6 +781,23 @@ public class TestReplaceText {
runner.assertAllFlowFilesTransferred(ReplaceText.REL_FAILURE, 1);
}
+ @Test
+ public void testRoutesToFailureIfLineTooLarge() throws IOException {
+ final TestRunner runner = getRunner();
+ runner.setProperty(ReplaceText.SEARCH_VALUE, "[123]");
+ runner.setProperty(ReplaceText.MAX_BUFFER_SIZE, "5 kb");
+ runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
+ runner.setProperty(ReplaceText.EVALUATION_MODE,
ReplaceText.LINE_BY_LINE);
+
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put("abc", "Good");
+
runner.enqueue(Paths.get("src/test/resources/TestReplaceTextLineByLine/apacheLicenseOnOneLine.txt"),
attributes);
+
+ runner.run();
+
+ runner.assertAllFlowFilesTransferred(ReplaceText.REL_FAILURE, 1);
+ }
+
@Test
public void testRoutesToSuccessIfTooLargeButRegexIsDotAsterisk() throws
IOException {
final TestRunner runner = getRunner();
diff --git
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestReplaceTextLineByLine/apacheLicenseOnOneLine.txt
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestReplaceTextLineByLine/apacheLicenseOnOneLine.txt
new file mode 100644
index 0000000000..627d7c8360
--- /dev/null
+++
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestReplaceTextLineByLine/apacheLicenseOnOneLine.txt
@@ -0,0 +1 @@
+Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS
AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document. "Licensor"
shall mean the copyright owner or entity authorized by the copyright owner that
is granting the License. "Legal Entity" shall mean the union of the acting
entity and all other entities that [...]