NIFI-10385: If script body is empty for AbstractScriptedControllerService or InvokeScriptedProcessor, do not attempt to load script

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #6324
This commit is contained in:
Mark Payne 2022-08-22 16:54:03 -04:00 committed by Matthew Burgess
parent 6bfc798515
commit cb275dd956
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24
2 changed files with 17 additions and 4 deletions

View File

@ -282,11 +282,14 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor {
* @return true if the script was loaded successfully; false otherwise
*/
private boolean reloadScriptFile(final String scriptPath) {
if (StringUtils.isEmpty(scriptPath)) {
return false;
}
final Collection<ValidationResult> results = new HashSet<>();
try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
return reloadScript(IOUtils.toString(scriptStream, Charset.defaultCharset()));
} catch (final Exception e) {
final ComponentLog logger = getLogger();
final String message = "Unable to load script: " + e;
@ -314,10 +317,13 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor {
* @return true if the script was loaded successfully; false otherwise
*/
private boolean reloadScriptBody(final String scriptBody) {
if (StringUtils.isEmpty(scriptBody)) {
return false;
}
final Collection<ValidationResult> results = new HashSet<>();
try {
return reloadScript(scriptBody);
} catch (final Exception e) {
final ComponentLog logger = getLogger();
final String message = "Unable to load script: " + e;

View File

@ -27,6 +27,7 @@ import org.apache.nifi.expression.ExpressionLanguageScope;
import org.apache.nifi.logging.ComponentLog;
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.processors.script.ScriptRunner;
import org.apache.nifi.util.StringUtils;
import java.io.FileInputStream;
import java.nio.charset.Charset;
@ -158,11 +159,14 @@ public abstract class AbstractScriptedControllerService extends AbstractControll
* @return true if the script was loaded successfully; false otherwise
*/
protected boolean reloadScriptFile(final String scriptPath) {
if (StringUtils.isEmpty(scriptPath)) {
return false;
}
final Collection<ValidationResult> results = new HashSet<>();
try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
return reloadScript(IOUtils.toString(scriptStream, Charset.defaultCharset()));
} catch (final Exception e) {
final ComponentLog logger = getLogger();
final String message = "Unable to load script: " + e;
@ -190,10 +194,13 @@ public abstract class AbstractScriptedControllerService extends AbstractControll
* @return true if the script was loaded successfully; false otherwise
*/
protected boolean reloadScriptBody(final String scriptBody) {
if (StringUtils.isEmpty(scriptBody)) {
return false;
}
final Collection<ValidationResult> results = new HashSet<>();
try {
return reloadScript(scriptBody);
} catch (final Exception e) {
final ComponentLog logger = getLogger();
final String message = "Unable to load script: " + e;