ARTEMIS-2759 Warn ignored connection factory URI parameters
This commit is contained in:
parent
e14ff38bae
commit
71d311322a
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
@ -115,6 +116,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<>();
|
||||
|
|
Loading…
Reference in New Issue