NIFI-3543 This closes #1548. Added support for using EL when defining brokerURL in jms-cf-service

Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
ShellyLC 2017-03-01 00:36:47 -08:00 committed by joewitt
parent 8ce2a1b3a7
commit 816034bd01
2 changed files with 22 additions and 6 deletions

View File

@ -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);

View File

@ -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);