You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/05/14 13:11:48 UTC
[activemq-artemis] branch master updated: ARTEMIS-2759 Warn ignored
connection factory URI parameters
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/master by this push:
new 71d3113 ARTEMIS-2759 Warn ignored connection factory URI parameters
new 28143ef This closes #3133
71d3113 is described below
commit 71d311322a973ede6cd9a834970b5c5d0e1b8848
Author: brusdev <br...@gmail.com>
AuthorDate: Thu May 14 06:04:50 2020 +0200
ARTEMIS-2759 Warn ignored connection factory URI parameters
---
.../activemq/artemis/utils/uri/URISchema.java | 6 ++++-
.../artemis/core/client/ActiveMQClientLogger.java | 5 ++++
.../org/apache/activemq/artemis/uri/TCPSchema.java | 30 +++++++++++++++++++++-
.../integration/jms/SimpleJNDIClientTest.java | 16 ++++++++++++
4 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java
index 49a84c1..0a9fd97 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java
@@ -31,7 +31,7 @@ public abstract class URISchema<T, P> {
}
public void populateObject(URI uri, T bean) throws Exception {
- BeanSupport.setData(uri, bean, parseQuery(uri.getQuery(), null));
+ internalPopulateObject(uri, parseQuery(uri.getQuery(), null), bean);
}
public URI newURI(T bean) throws Exception {
@@ -99,6 +99,10 @@ public abstract class URISchema<T, P> {
}
+ protected void internalPopulateObject(URI uri, Map<String, String> query, T bean) throws Exception {
+ BeanSupport.setData(uri, bean, query);
+ }
+
public static Map<String, String> parseQuery(String uri,
Map<String, String> propertyOverrides) throws URISyntaxException {
try {
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
index 9eebed8..3dbf44d 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/ActiveMQClientLogger.java
@@ -425,6 +425,11 @@ public interface ActiveMQClientLogger extends BasicLogger {
format = Message.Format.MESSAGE_FORMAT)
void broadcastTimeout(int retry, int maxretry);
+ @LogMessage(level = Logger.Level.WARN)
+ @Message(id = 212078, value = "Connection factory parameter ignored {0}",
+ format = Message.Format.MESSAGE_FORMAT)
+ void connectionFactoryParameterIgnored(String parameterName);
+
@LogMessage(level = Logger.Level.ERROR)
@Message(id = 214000, value = "Failed to call onMessage", format = Message.Format.MESSAGE_FORMAT)
void onMessageError(@Cause Throwable e);
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/uri/TCPSchema.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/uri/TCPSchema.java
index eddff33..f97da98 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/uri/TCPSchema.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/uri/TCPSchema.java
@@ -19,9 +19,11 @@ package org.apache.activemq.artemis.uri;
import java.net.URI;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
@@ -57,7 +59,33 @@ public class TCPSchema extends AbstractCFSchema {
factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), tcs);
}
- return setData(uri, query, factory);
+ setData(uri, query, factory);
+
+ checkIgnoredQueryFields(factory, query);
+
+ return factory;
+ }
+
+ @Override
+ protected void internalPopulateObject(URI uri,
+ Map<String, String> query,
+ ActiveMQConnectionFactory bean) throws Exception {
+ super.internalPopulateObject(uri, query, bean);
+
+ checkIgnoredQueryFields(bean, query);
+ }
+
+ private void checkIgnoredQueryFields(ActiveMQConnectionFactory factory, Map<String, String> query) throws Exception {
+ Properties factoryProperties = new Properties();
+ BeanSupport.getProperties(factory, factoryProperties);
+
+ for (String key: query.keySet()) {
+ if (!key.equals("ha") && !key.equals("type") &&
+ !TransportConstants.ALLOWABLE_CONNECTOR_KEYS.contains(key) &&
+ !factoryProperties.containsKey(key)) {
+ ActiveMQClientLogger.LOGGER.connectionFactoryParameterIgnored(key);
+ }
+ }
}
@Override
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
index c93f67b..f6cbb24 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java
@@ -57,6 +57,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory;
+import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.Assert;
@@ -116,6 +117,21 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
}
@Test
+ public void testConnectionFactoryStringWithInvalidParameter() throws Exception {
+ Hashtable<String, String> props = new Hashtable<>();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
+ props.put("connectionFactory.ConnectionFactory", "tcp://localhost:61616?foo=too");
+
+ AssertionLoggerHandler.startCapture();
+ try {
+ new InitialContext(props);
+ assertTrue("Expected to find AMQ212078", AssertionLoggerHandler.findText("AMQ212078"));
+ } finally {
+ AssertionLoggerHandler.stopCapture();
+ }
+ }
+
+ @Test
public void testVMCF1() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");