You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by markap14 <gi...@git.apache.org> on 2018/09/14 14:49:53 UTC
[GitHub] nifi pull request #3005: NIFI-5598: Allow JMS Processors to lookup Connectio...
GitHub user markap14 opened a pull request:
https://github.com/apache/nifi/pull/3005
NIFI-5598: Allow JMS Processors to lookup Connection Factory via JNDI
Thank you for submitting a contribution to Apache NiFi.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
- [ ] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
- [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
- [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/markap14/nifi NIFI-5598
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi/pull/3005.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #3005
----
commit 4d7313aac0dcbc2b2533e3c2581240020bcb9037
Author: Mark Payne <ma...@...>
Date: 2018-09-14T14:48:59Z
NIFI-5598: Allow JMS Processors to lookup Connection Factory via JNDI
----
---
[GitHub] nifi issue #3005: NIFI-5598: Allow JMS Processors to lookup Connection Facto...
Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:
https://github.com/apache/nifi/pull/3005
+1 LGTM, reviewed code and ran unit tests. @bdesert tried with success on a running system. Thanks for the improvement! Merging to master
---
[GitHub] nifi pull request #3005: NIFI-5598: Allow JMS Processors to lookup Connectio...
Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/3005#discussion_r218438047
--- Diff: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JndiJmsConnectionFactoryProvider.java ---
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.jms.cf;
+
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyDescriptor.Builder;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
+import static org.apache.nifi.processor.util.StandardValidators.NON_EMPTY_VALIDATOR;
+
+@Tags({"jms", "jndi", "messaging", "integration", "queue", "topic", "publish", "subscribe"})
+@CapabilityDescription("Provides a service to lookup an existing JMS ConnectionFactory using the Java Naming and Directory Interface (JNDI).")
+@DynamicProperty(
+ description = "In order to perform a JNDI Lookup, an Initial Context must be established. When this is done, an Environment can be established for the context. Any dynamic/user-defined property" +
+ " that is added to this Controller Service will be added as an Environment configuration/variable to this Context.",
+ name = "The name of a JNDI Initial Context environment variable.",
+ value = "The value of the JNDI Initial Context Environment variable.",
+ expressionLanguageScope = ExpressionLanguageScope.VARIABLE_REGISTRY)
+@SeeAlso(classNames = {"org.apache.nifi.jms.processors.ConsumeJMS", "org.apache.nifi.jms.processors.PublishJMS", "org.apache.nifi.jms.cf.JMSConnectionFactoryProvider"})
+public class JndiJmsConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition{
+
+ static final PropertyDescriptor INITIAL_NAMING_FACTORY_CLASS = new Builder()
+ .name("java.naming.factory.initial")
+ .displayName("Initial Naming Factory Class")
+ .description("The fully qualified class name of the Java Initial Naming Factory (java.naming.factory.initial).")
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .required(true)
+ .build();
+ static final PropertyDescriptor NAMING_PROVIDER_URL = new Builder()
+ .name("java.naming.provider.url")
+ .displayName("Naming Provider URL")
+ .description("The URL of the JNDI Naming Provider to use")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor CONNECTION_FACTORY_NAME = new Builder()
+ .name("connection.factory.name")
+ .displayName("Connection Factory Name")
+ .description("The name of the JNDI Object to lookup for the Connection Factory")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor NAMING_FACTORY_LIBRARIES = new Builder()
+ .name("naming.factory.libraries")
+ .displayName("Naming Factory Libraries")
+ .description("Specifies .jar files or directories to add to the ClassPath in order to find the Initial Naming Factory Class")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .addValidator(StandardValidators.createListValidator(true, true, StandardValidators.createURLorFileValidator()))
+ .dynamicallyModifiesClasspath(true)
+ .build();
+
+ private static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = Arrays.asList(
+ INITIAL_NAMING_FACTORY_CLASS,
+ NAMING_PROVIDER_URL,
+ CONNECTION_FACTORY_NAME,
+ NAMING_FACTORY_LIBRARIES);
+
+ private ConnectionFactory connectionFactory;
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return PROPERTY_DESCRIPTORS;
+ }
+
+ @Override
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
+ return new Builder()
+ .name(propertyDescriptorName)
+ .displayName(propertyDescriptorName)
+ .description("JNDI Initial Context Environment configuration for '" + propertyDescriptorName + "'")
+ .required(false)
+ .dynamic(true)
+ .addValidator(Validator.VALID)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ }
+
+ @OnDisabled
+ public void shutdown() {
+ connectionFactory = null;
+ }
+
+ @Override
+ public synchronized ConnectionFactory getConnectionFactory() {
--- End diff --
No, the above code is not thread safe. All access to the member variable must be protected. Synchronization is not a concern here. Either the method returns immediately or blocks while creating the connection factory, which is the desired behavior.
---
[GitHub] nifi pull request #3005: NIFI-5598: Allow JMS Processors to lookup Connectio...
Posted by bdesert <gi...@git.apache.org>.
Github user bdesert commented on a diff in the pull request:
https://github.com/apache/nifi/pull/3005#discussion_r218387623
--- Diff: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JndiJmsConnectionFactoryProvider.java ---
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.jms.cf;
+
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyDescriptor.Builder;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
+import static org.apache.nifi.processor.util.StandardValidators.NON_EMPTY_VALIDATOR;
+
+@Tags({"jms", "jndi", "messaging", "integration", "queue", "topic", "publish", "subscribe"})
+@CapabilityDescription("Provides a service to lookup an existing JMS ConnectionFactory using the Java Naming and Directory Interface (JNDI).")
+@DynamicProperty(
+ description = "In order to perform a JNDI Lookup, an Initial Context must be established. When this is done, an Environment can be established for the context. Any dynamic/user-defined property" +
+ " that is added to this Controller Service will be added as an Environment configuration/variable to this Context.",
+ name = "The name of a JNDI Initial Context environment variable.",
+ value = "The value of the JNDI Initial Context Environment variable.",
+ expressionLanguageScope = ExpressionLanguageScope.VARIABLE_REGISTRY)
+@SeeAlso(classNames = {"org.apache.nifi.jms.processors.ConsumeJMS", "org.apache.nifi.jms.processors.PublishJMS", "org.apache.nifi.jms.cf.JMSConnectionFactoryProvider"})
+public class JndiJmsConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition{
+
+ static final PropertyDescriptor INITIAL_NAMING_FACTORY_CLASS = new Builder()
+ .name("java.naming.factory.initial")
+ .displayName("Initial Naming Factory Class")
+ .description("The fully qualified class name of the Java Initial Naming Factory (java.naming.factory.initial).")
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .required(true)
+ .build();
+ static final PropertyDescriptor NAMING_PROVIDER_URL = new Builder()
+ .name("java.naming.provider.url")
+ .displayName("Naming Provider URL")
+ .description("The URL of the JNDI Naming Provider to use")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor CONNECTION_FACTORY_NAME = new Builder()
+ .name("connection.factory.name")
+ .displayName("Connection Factory Name")
+ .description("The name of the JNDI Object to lookup for the Connection Factory")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor NAMING_FACTORY_LIBRARIES = new Builder()
+ .name("naming.factory.libraries")
+ .displayName("Naming Factory Libraries")
+ .description("Specifies .jar files or directories to add to the ClassPath in order to find the Initial Naming Factory Class")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .addValidator(StandardValidators.createListValidator(true, true, StandardValidators.createURLorFileValidator()))
+ .dynamicallyModifiesClasspath(true)
+ .build();
+
+ private static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = Arrays.asList(
+ INITIAL_NAMING_FACTORY_CLASS,
+ NAMING_PROVIDER_URL,
+ CONNECTION_FACTORY_NAME,
+ NAMING_FACTORY_LIBRARIES);
+
+ private ConnectionFactory connectionFactory;
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return PROPERTY_DESCRIPTORS;
+ }
+
+ @Override
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
+ return new Builder()
+ .name(propertyDescriptorName)
+ .displayName(propertyDescriptorName)
+ .description("JNDI Initial Context Environment configuration for '" + propertyDescriptorName + "'")
+ .required(false)
+ .dynamic(true)
+ .addValidator(Validator.VALID)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ }
+
+ @OnDisabled
+ public void shutdown() {
+ connectionFactory = null;
+ }
+
+ @Override
+ public synchronized ConnectionFactory getConnectionFactory() {
+ if (connectionFactory == null) {
+ connectionFactory = lookupConnectionFactory();
+ } else {
+ getLogger().debug("Connection Factory has already been obtained from JNDI. Will return cached instance.");
+ }
+
+ return connectionFactory;
+ }
+
+ private ConnectionFactory lookupConnectionFactory() {
+ try {
+ final ConfigurationContext context = getConfigurationContext();
+
+ final Hashtable env = new Hashtable();
--- End diff --
Hashtable support generics. Can it be parametrized?
final Hashtable<String,String> env = new Hashtable<>();
---
[GitHub] nifi pull request #3005: NIFI-5598: Allow JMS Processors to lookup Connectio...
Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/3005#discussion_r218439155
--- Diff: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JndiJmsConnectionFactoryProvider.java ---
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.jms.cf;
+
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyDescriptor.Builder;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
+import static org.apache.nifi.processor.util.StandardValidators.NON_EMPTY_VALIDATOR;
+
+@Tags({"jms", "jndi", "messaging", "integration", "queue", "topic", "publish", "subscribe"})
+@CapabilityDescription("Provides a service to lookup an existing JMS ConnectionFactory using the Java Naming and Directory Interface (JNDI).")
+@DynamicProperty(
+ description = "In order to perform a JNDI Lookup, an Initial Context must be established. When this is done, an Environment can be established for the context. Any dynamic/user-defined property" +
+ " that is added to this Controller Service will be added as an Environment configuration/variable to this Context.",
+ name = "The name of a JNDI Initial Context environment variable.",
+ value = "The value of the JNDI Initial Context Environment variable.",
+ expressionLanguageScope = ExpressionLanguageScope.VARIABLE_REGISTRY)
+@SeeAlso(classNames = {"org.apache.nifi.jms.processors.ConsumeJMS", "org.apache.nifi.jms.processors.PublishJMS", "org.apache.nifi.jms.cf.JMSConnectionFactoryProvider"})
+public class JndiJmsConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition{
+
+ static final PropertyDescriptor INITIAL_NAMING_FACTORY_CLASS = new Builder()
+ .name("java.naming.factory.initial")
+ .displayName("Initial Naming Factory Class")
+ .description("The fully qualified class name of the Java Initial Naming Factory (java.naming.factory.initial).")
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .required(true)
+ .build();
+ static final PropertyDescriptor NAMING_PROVIDER_URL = new Builder()
+ .name("java.naming.provider.url")
+ .displayName("Naming Provider URL")
+ .description("The URL of the JNDI Naming Provider to use")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor CONNECTION_FACTORY_NAME = new Builder()
+ .name("connection.factory.name")
+ .displayName("Connection Factory Name")
+ .description("The name of the JNDI Object to lookup for the Connection Factory")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor NAMING_FACTORY_LIBRARIES = new Builder()
+ .name("naming.factory.libraries")
+ .displayName("Naming Factory Libraries")
+ .description("Specifies .jar files or directories to add to the ClassPath in order to find the Initial Naming Factory Class")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .addValidator(StandardValidators.createListValidator(true, true, StandardValidators.createURLorFileValidator()))
+ .dynamicallyModifiesClasspath(true)
+ .build();
+
+ private static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = Arrays.asList(
+ INITIAL_NAMING_FACTORY_CLASS,
+ NAMING_PROVIDER_URL,
+ CONNECTION_FACTORY_NAME,
+ NAMING_FACTORY_LIBRARIES);
+
+ private ConnectionFactory connectionFactory;
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return PROPERTY_DESCRIPTORS;
+ }
+
+ @Override
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
+ return new Builder()
+ .name(propertyDescriptorName)
+ .displayName(propertyDescriptorName)
+ .description("JNDI Initial Context Environment configuration for '" + propertyDescriptorName + "'")
+ .required(false)
+ .dynamic(true)
+ .addValidator(Validator.VALID)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ }
+
+ @OnDisabled
+ public void shutdown() {
+ connectionFactory = null;
+ }
+
+ @Override
+ public synchronized ConnectionFactory getConnectionFactory() {
+ if (connectionFactory == null) {
+ connectionFactory = lookupConnectionFactory();
+ } else {
+ getLogger().debug("Connection Factory has already been obtained from JNDI. Will return cached instance.");
+ }
+
+ return connectionFactory;
+ }
+
+ private ConnectionFactory lookupConnectionFactory() {
+ try {
+ final ConfigurationContext context = getConfigurationContext();
+
+ final Hashtable env = new Hashtable();
--- End diff --
Good call.
---
[GitHub] nifi pull request #3005: NIFI-5598: Allow JMS Processors to lookup Connectio...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/nifi/pull/3005
---
[GitHub] nifi issue #3005: NIFI-5598: Allow JMS Processors to lookup Connection Facto...
Posted by bdesert <gi...@git.apache.org>.
Github user bdesert commented on the issue:
https://github.com/apache/nifi/pull/3005
+1. Ready for merge.
Tested JNDI lookup with Tibco Context Factory (with authentication). Successfully pulled records from my queue.
---
[GitHub] nifi issue #3005: NIFI-5598: Allow JMS Processors to lookup Connection Facto...
Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on the issue:
https://github.com/apache/nifi/pull/3005
@bdesert thanks for the great feedback. I have pushed another commit.
---
[GitHub] nifi pull request #3005: NIFI-5598: Allow JMS Processors to lookup Connectio...
Posted by bdesert <gi...@git.apache.org>.
Github user bdesert commented on a diff in the pull request:
https://github.com/apache/nifi/pull/3005#discussion_r218386884
--- Diff: nifi-nar-bundles/nifi-jms-bundle/nifi-jms-processors/src/main/java/org/apache/nifi/jms/cf/JndiJmsConnectionFactoryProvider.java ---
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.jms.cf;
+
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyDescriptor.Builder;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import javax.jms.ConnectionFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
+import static org.apache.nifi.processor.util.StandardValidators.NON_EMPTY_VALIDATOR;
+
+@Tags({"jms", "jndi", "messaging", "integration", "queue", "topic", "publish", "subscribe"})
+@CapabilityDescription("Provides a service to lookup an existing JMS ConnectionFactory using the Java Naming and Directory Interface (JNDI).")
+@DynamicProperty(
+ description = "In order to perform a JNDI Lookup, an Initial Context must be established. When this is done, an Environment can be established for the context. Any dynamic/user-defined property" +
+ " that is added to this Controller Service will be added as an Environment configuration/variable to this Context.",
+ name = "The name of a JNDI Initial Context environment variable.",
+ value = "The value of the JNDI Initial Context Environment variable.",
+ expressionLanguageScope = ExpressionLanguageScope.VARIABLE_REGISTRY)
+@SeeAlso(classNames = {"org.apache.nifi.jms.processors.ConsumeJMS", "org.apache.nifi.jms.processors.PublishJMS", "org.apache.nifi.jms.cf.JMSConnectionFactoryProvider"})
+public class JndiJmsConnectionFactoryProvider extends AbstractControllerService implements JMSConnectionFactoryProviderDefinition{
+
+ static final PropertyDescriptor INITIAL_NAMING_FACTORY_CLASS = new Builder()
+ .name("java.naming.factory.initial")
+ .displayName("Initial Naming Factory Class")
+ .description("The fully qualified class name of the Java Initial Naming Factory (java.naming.factory.initial).")
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .required(true)
+ .build();
+ static final PropertyDescriptor NAMING_PROVIDER_URL = new Builder()
+ .name("java.naming.provider.url")
+ .displayName("Naming Provider URL")
+ .description("The URL of the JNDI Naming Provider to use")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor CONNECTION_FACTORY_NAME = new Builder()
+ .name("connection.factory.name")
+ .displayName("Connection Factory Name")
+ .description("The name of the JNDI Object to lookup for the Connection Factory")
+ .required(true)
+ .addValidator(NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ static final PropertyDescriptor NAMING_FACTORY_LIBRARIES = new Builder()
+ .name("naming.factory.libraries")
+ .displayName("Naming Factory Libraries")
+ .description("Specifies .jar files or directories to add to the ClassPath in order to find the Initial Naming Factory Class")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .addValidator(StandardValidators.createListValidator(true, true, StandardValidators.createURLorFileValidator()))
+ .dynamicallyModifiesClasspath(true)
+ .build();
+
+ private static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = Arrays.asList(
+ INITIAL_NAMING_FACTORY_CLASS,
+ NAMING_PROVIDER_URL,
+ CONNECTION_FACTORY_NAME,
+ NAMING_FACTORY_LIBRARIES);
+
+ private ConnectionFactory connectionFactory;
+
+ @Override
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return PROPERTY_DESCRIPTORS;
+ }
+
+ @Override
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
+ return new Builder()
+ .name(propertyDescriptorName)
+ .displayName(propertyDescriptorName)
+ .description("JNDI Initial Context Environment configuration for '" + propertyDescriptorName + "'")
+ .required(false)
+ .dynamic(true)
+ .addValidator(Validator.VALID)
+ .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
+ .build();
+ }
+
+ @OnDisabled
+ public void shutdown() {
+ connectionFactory = null;
+ }
+
+ @Override
+ public synchronized ConnectionFactory getConnectionFactory() {
--- End diff --
since this method is called each onTrigger I could be better to have two steps instantiation (to avoid sync for each call):
@Override
public ConnectionFactory getConnectionFactory() {
return connectionFactory != null ? connectionFactory : _getConnectionFactory();
}
private synchronized ConnectionFactory _getConnectionFactory() {
if (connectionFactory == null) {
connectionFactory = lookupConnectionFactory();
} else {
getLogger().debug("Connection Factory has already been obtained from JNDI. Will return cached instance.");
}
return connectionFactory;
}
---
[GitHub] nifi issue #3005: NIFI-5598: Allow JMS Processors to lookup Connection Facto...
Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on the issue:
https://github.com/apache/nifi/pull/3005
@bdesert fair enough re: sensitive property & credentials.
---
[GitHub] nifi issue #3005: NIFI-5598: Allow JMS Processors to lookup Connection Facto...
Posted by bdesert <gi...@git.apache.org>.
Github user bdesert commented on the issue:
https://github.com/apache/nifi/pull/3005
I'll test it and will let you know results (I have JNDI server with authentication for JMS queues).
---