Repository: qpid-jms Updated Branches: refs/heads/master bb12ef788 -> 368dce70b
QPIDJMS-250 Report invalid remote URIs with consistent errors Throw a consistent IllegalArgumentException for invalid remote URI inputs. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/368dce70 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/368dce70 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/368dce70 Branch: refs/heads/master Commit: 368dce70b8625b27e57137e71153554ff58fc384 Parents: bb12ef7 Author: Timothy Bish <tabish...@gmail.com> Authored: Fri Jan 13 11:11:33 2017 -0500 Committer: Timothy Bish <tabish...@gmail.com> Committed: Fri Jan 13 11:11:33 2017 -0500 ---------------------------------------------------------------------- .../apache/qpid/jms/JmsConnectionFactory.java | 22 ++++----- .../qpid/jms/JmsConnectionFactoryTest.java | 50 +++++++++++++++++++- 2 files changed, 59 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/368dce70/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java index 644f960..c455447 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java @@ -116,23 +116,23 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact } public JmsConnectionFactory(String remoteURI) { - setRemoteURI(remoteURI); + setRemoteURI(remoteURI == null ? null : remoteURI); } - public JmsConnectionFactory(URI remoteURI) { - setRemoteURI(remoteURI.toString()); - } - - public JmsConnectionFactory(String userName, String password, URI remoteURI) { + public JmsConnectionFactory(String userName, String password, String remoteURI) { setUsername(userName); setPassword(password); - setRemoteURI(remoteURI.toString()); + setRemoteURI(remoteURI == null ? null : remoteURI); } - public JmsConnectionFactory(String userName, String password, String remoteURI) { + public JmsConnectionFactory(URI remoteURI) { + setRemoteURI(remoteURI == null ? null : remoteURI.toString()); + } + + public JmsConnectionFactory(String userName, String password, URI remoteURI) { setUsername(userName); setPassword(password); - setRemoteURI(remoteURI); + setRemoteURI(remoteURI == null ? null : remoteURI.toString()); } @Override @@ -376,8 +376,8 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact * the remoteURI to set */ public void setRemoteURI(String remoteURI) { - if (remoteURI == null) { - throw new IllegalArgumentException("remoteURI cannot be null"); + if (remoteURI == null || remoteURI.isEmpty()) { + throw new IllegalArgumentException("Invalid URI: cannot be null or empty"); } this.remoteURI = createURI(remoteURI); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/368dce70/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java index b34f486..1817956 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java @@ -637,17 +637,54 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase { } @Test + public void testSetRemoteURIThrowsOnEmptyStringURI() throws Exception { + JmsConnectionFactory cf = new JmsConnectionFactory(); + try { + cf.setRemoteURI(""); + fail("Should not allow a empty URI to be set."); + } catch (IllegalArgumentException e) { + } + } + + @Test public void testCreateWithNullURIRemoteURIThrows() throws Exception { try { - new JmsConnectionFactory("user", "pass", (URI) null); + new JmsConnectionFactory((URI) null); fail("Should not allow a null URI to be set."); - } catch (NullPointerException e) { + } catch (IllegalArgumentException e) { } } @Test public void testCreateWithNullURIStringRemoteURIThrows() throws Exception { try { + new JmsConnectionFactory((String) null); + fail("Should not allow a null URI to be set."); + } catch (IllegalArgumentException e) { + } + } + + @Test + public void testCreateWithEmptyURIStringRemoteURIThrows() throws Exception { + try { + new JmsConnectionFactory(""); + fail("Should not allow a empty URI string to be set."); + } catch (IllegalArgumentException e) { + } + } + + @Test + public void testCreateWithCredentialsWithNullURIRemoteURIThrows() throws Exception { + try { + new JmsConnectionFactory("user", "pass", (URI) null); + fail("Should not allow a null URI to be set."); + } catch (IllegalArgumentException e) { + } + } + + @Test + public void testCreateWithCredentialsWithNullURIStringRemoteURIThrows() throws Exception { + try { new JmsConnectionFactory("user", "pass", (String) null); fail("Should not allow a null URI to be set."); } catch (IllegalArgumentException e) { @@ -655,6 +692,15 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase { } @Test + public void testCreateWithCredentialsWithEmptyURIStringRemoteURIThrows() throws Exception { + try { + new JmsConnectionFactory("user", "pass", ""); + fail("Should not allow a empty URI string to be set."); + } catch (IllegalArgumentException e) { + } + } + + @Test public void testSerializeTwoConnectionFactories() throws Exception { String uri = "amqp://localhost:1234"; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org