From 816034bd01c2ac2ee480f6a82aca146e250c2101 Mon Sep 17 00:00:00 2001 From: ShellyLC Date: Wed, 1 Mar 2017 00:36:47 -0800 Subject: [PATCH] NIFI-3543 This closes #1548. Added support for using EL when defining brokerURL in jms-cf-service Signed-off-by: joewitt --- .../jms/cf/JMSConnectionFactoryProvider.java | 9 +++++---- ...MSConnectionFactoryProviderDefinition.java | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProvider.java b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProvider.java index 32ff78c629..d21b0be36f 100644 --- a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProvider.java +++ b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProvider.java @@ -177,17 +177,18 @@ public class JMSConnectionFactoryProvider extends AbstractControllerService impl this.setProperty(propertyName, entry.getValue()); } else { if (propertyName.equals(BROKER)) { + String brokerValue = context.getProperty(descriptor).evaluateAttributeExpressions().getValue(); if (context.getProperty(CONNECTION_FACTORY_IMPL).evaluateAttributeExpressions().getValue().startsWith("org.apache.activemq")) { - this.setProperty("brokerURL", entry.getValue()); + this.setProperty("brokerURL", brokerValue); } else { - String[] hostPort = entry.getValue().split(":"); + String[] hostPort = brokerValue.split(":"); if (hostPort.length == 2) { this.setProperty("hostName", hostPort[0]); this.setProperty("port", hostPort[1]); } else if (hostPort.length != 2) { - this.setProperty("serverUrl", entry.getValue()); // for tibco + this.setProperty("serverUrl", brokerValue); // for tibco } else { - throw new IllegalArgumentException("Failed to parse broker url: " + entry.getValue()); + throw new IllegalArgumentException("Failed to parse broker url: " + brokerValue); } } SSLContextService sc = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class); diff --git a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderDefinition.java b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderDefinition.java index 3057ec6bab..c3afd32ed2 100644 --- a/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderDefinition.java +++ b/nifi-nar-bundles/nifi-jms-bundle/nifi-jms-cf-service/src/main/java/org/apache/nifi/jms/cf/JMSConnectionFactoryProviderDefinition.java @@ -63,7 +63,7 @@ public interface JMSConnectionFactoryProviderDefinition extends ControllerServic .displayName("Broker URI") .description("URI pointing to the network location of the JMS Message broker. For example, " + "'tcp://myhost:61616' for ActiveMQ or 'myhost:1414' for IBM MQ") - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .addValidator(new NonEmptyBrokerURIValidator()) .required(true) .expressionLanguageSupported(true) .build(); @@ -86,13 +86,28 @@ public interface JMSConnectionFactoryProviderDefinition extends ControllerServic */ ConnectionFactory getConnectionFactory(); + /** + * {@link Validator} that ensures that brokerURI's length > 0 after EL evaluation + */ + static class NonEmptyBrokerURIValidator implements Validator { + + @Override + public ValidationResult validate(String subject, String input, ValidationContext context) { + String value = input; + if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) { + value = context.getProperty(BROKER_URI).evaluateAttributeExpressions().getValue(); + } + return StandardValidators.NON_EMPTY_VALIDATOR.validate(subject, value, context); + } + } + /** * */ static class ClientLibValidator implements Validator { @Override public ValidationResult validate(String subject, String input, ValidationContext context) { - String libDirPath = context.getProperty(CLIENT_LIB_DIR_PATH).getValue(); + String libDirPath = context.getProperty(CLIENT_LIB_DIR_PATH).evaluateAttributeExpressions().getValue(); StringBuilder invalidationMessageBuilder = new StringBuilder(); if (libDirPath != null) { File file = new File(libDirPath);