ensure exception messages from the context factory during creation actually give users some/any indication what the problem was
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
index 3f2423d..691eb81 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/jndi/JmsInitialContextFactory.java
@@ -105,7 +105,9 @@
try {
factory = createConnectionFactory(name, defaults, environment);
} catch (Exception e) {
- throw new NamingException("Invalid ConnectionFactory definition");
+ NamingException ne = new NamingException("Exception while creating ConnectionFactory '" + name + "'.");
+ ne.initCause(e);
+ throw ne;
}
bindings.put(name, factory);
@@ -138,7 +140,7 @@
// Add any factory-specific additional properties
props.putAll(getConnectionFactoryProperties(name, environment));
- return createConnectionFactory(name, props);
+ return createConnectionFactory(props);
}
protected List<String> getConnectionFactoryNames(Map<Object, Object> environment) {
@@ -232,12 +234,12 @@
/**
* Factory method to create a new connection factory using the given properties
*/
- protected JmsConnectionFactory createConnectionFactory(String name, Map<String, String> properties) throws URISyntaxException {
+ protected JmsConnectionFactory createConnectionFactory(Map<String, String> properties) {
JmsConnectionFactory factory = new JmsConnectionFactory();
Map<String, String> unused = factory.setProperties(properties);
if (!unused.isEmpty()) {
String msg =
- " Not all properties could be set on ConnectionFactory '" + name + "'."
+ " Not all properties could be set on the ConnectionFactory."
+ " Check the properties are spelled correctly."
+ " Unused properties=[" + unused + "].";
throw new IllegalArgumentException(msg);
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
index d94fb41..c2b9b4b 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java
@@ -141,6 +141,7 @@
fail("Should have thrown exception");
} catch (NamingException ne) {
// Expected
+ assertTrue("Should have had a cause", ne.getCause() != null);
}
}
@@ -160,6 +161,7 @@
fail("Should have thrown exception");
} catch (NamingException ne) {
// Expected
+ assertTrue("Should have had a cause", ne.getCause() != null);
}
}