This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-api.git


The following commit(s) were added to refs/heads/main by this push:
     new 342b4e9  NIFI-15983 Added HOSTNAME_PORT_VALIDATOR to 
StandardValidators (#91)
342b4e9 is described below

commit 342b4e9532d9d2949a2d6ab4641f637f9c0a7bd4
Author: Hiroyuki Yagihashi <[email protected]>
AuthorDate: Wed Jun 3 04:08:34 2026 +0900

    NIFI-15983 Added HOSTNAME_PORT_VALIDATOR to StandardValidators (#91)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../nifi/processor/util/StandardValidators.java    | 55 +++++++++++++++-------
 1 file changed, 38 insertions(+), 17 deletions(-)

diff --git 
a/src/main/java/org/apache/nifi/processor/util/StandardValidators.java 
b/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
index 26d88c7..aeecc3a 100644
--- a/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
+++ b/src/main/java/org/apache/nifi/processor/util/StandardValidators.java
@@ -182,36 +182,23 @@ public class StandardValidators {
      * {@link Validator} that ensures that value is a non-empty comma 
separated list of hostname:port
      */
     public static final Validator HOSTNAME_PORT_LIST_VALIDATOR = new 
Validator() {
-        private static final Validator NON_ZERO_PORT_VALIDATOR = 
createLongValidator(1, 65535, true);
-
         @Override
         public ValidationResult validate(String subject, String input, 
ValidationContext context) {
-            // expression language
             if (context.isExpressionLanguageSupported(subject) && 
context.isExpressionLanguagePresent(input)) {
                 return new 
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
 Language Present").valid(true).build();
             }
 
-            // not empty
             final ValidationResult nonEmptyValidatorResult = 
NON_EMPTY_VALIDATOR.validate(subject, input, context);
             if (!nonEmptyValidatorResult.isValid()) {
                 return nonEmptyValidatorResult;
             }
 
-            // check format
             final String[] hostnamePortList = input.split(",");
-            for (String hostnamePort : hostnamePortList) {
-                final String[] addresses = hostnamePort.split(":");
-                // Protect against invalid input like http://127.0.0.1:9300 
(URL scheme should not be there)
-                if (addresses.length != 2) {
-                    return new 
ValidationResult.Builder().subject(subject).input(input).explanation(
-                            "Must be in hostname:port form (no scheme such as 
http://";).valid(false).build();
-                }
 
-                // Validate the port
-                final String port = addresses[1].trim();
-                final ValidationResult portValidatorResult = 
NON_ZERO_PORT_VALIDATOR.validate(subject, port, context);
-                if (!portValidatorResult.isValid()) {
-                    return portValidatorResult;
+            for (String hostnamePort : hostnamePortList) {
+                final ValidationResult result = 
HOSTNAME_PORT_VALIDATOR.validate(subject, hostnamePort.trim(), context);
+                if (!result.isValid()) {
+                    return result;
                 }
             }
 
@@ -219,6 +206,40 @@ public class StandardValidators {
         }
     };
 
+    /**
+     * {@link Validator} that ensures that value is a non-empty hostname:port
+     */
+    public static final Validator HOSTNAME_PORT_VALIDATOR = new Validator() {
+        private static final Validator NON_ZERO_PORT_VALIDATOR = 
createLongValidator(1, 65535, true);
+
+        @Override
+        public ValidationResult validate(String subject, String input, 
ValidationContext context) {
+            if (context.isExpressionLanguageSupported(subject) && 
context.isExpressionLanguagePresent(input)) {
+                return new 
ValidationResult.Builder().subject(subject).input(input).explanation("Expression
 Language Present").valid(true).build();
+            }
+
+            final ValidationResult nonEmptyValidatorResult = 
NON_EMPTY_VALIDATOR.validate(subject, input, context);
+            if (!nonEmptyValidatorResult.isValid()) {
+                return nonEmptyValidatorResult;
+            }
+
+            final String[] addresses = input.trim().split(":");
+            // Protect against invalid input like http://127.0.0.1:9300 (URL 
scheme should not be there)
+            if (addresses.length != 2) {
+                return new 
ValidationResult.Builder().subject(subject).input(input).explanation(
+                        "Must be in hostname:port form (no scheme such as 
http://)").valid(false).build();
+            }
+
+            final String port = addresses[1].trim();
+            final ValidationResult portValidatorResult = 
NON_ZERO_PORT_VALIDATOR.validate(subject, port, context);
+            if (!portValidatorResult.isValid()) {
+                return portValidatorResult;
+            }
+
+            return new 
ValidationResult.Builder().subject(subject).input(input).explanation("Valid 
hostname:port").valid(true).build();
+        }
+    };
+
     /**
      * {@link Validator} that ensures that value has 1+ non-whitespace
      * characters

Reply via email to