summaryrefslogtreecommitdiff
path: root/java/client
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2012-05-28 12:20:35 +0000
committerRobert Gemmell <robbie@apache.org>2012-05-28 12:20:35 +0000
commit2e94295802a69fd5e94e2df8ca1a3f9429439b1d (patch)
tree0281ecf916ea5921a79f15599d79af77ff020150 /java/client
parent248fa27fa45dab6e958a0aeb990fa51f3d1f12ed (diff)
downloadqpid-python-2e94295802a69fd5e94e2df8ca1a3f9429439b1d.tar.gz
QPID-4023: restore connection URL setter, add check that URL details have been set before calling connect(), add unit+sys test to verify operation
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1343220 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client')
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java20
-rw-r--r--java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java (renamed from java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java)20
2 files changed, 34 insertions, 6 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
index cc91746d98..8bc815d98e 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
@@ -55,12 +55,13 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
ObjectFactory, Referenceable, XATopicConnectionFactory,
XAQueueConnectionFactory, XAConnectionFactory
{
- private final ConnectionURL _connectionDetails;
+ protected static final String NO_URL_CONFIGURED = "The connection factory wasn't created with a proper URL, the connection details are empty";
+
+ private ConnectionURL _connectionDetails;
// The default constructor is necessary to allow AMQConnectionFactory to be deserialised from JNDI
public AMQConnectionFactory()
{
- _connectionDetails = null;
}
public AMQConnectionFactory(final String url) throws URLSyntaxException
@@ -106,6 +107,11 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
public Connection createConnection() throws JMSException
{
+ if(_connectionDetails == null)
+ {
+ throw new JMSException(NO_URL_CONFIGURED);
+ }
+
try
{
if (_connectionDetails.getClientName() == null || _connectionDetails.getClientName().equals(""))
@@ -158,7 +164,7 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
}
else
{
- throw new JMSException("The connection factory wasn't created with a proper URL, the connection details are empty");
+ throw new JMSException(NO_URL_CONFIGURED);
}
}
@@ -193,6 +199,12 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
return _connectionDetails.toString();
}
+ //setter necessary to use instances created with the default constructor (which we can't remove)
+ public final void setConnectionURLString(String url) throws URLSyntaxException
+ {
+ _connectionDetails = new AMQConnectionURL(url);
+ }
+
/**
* JNDI interface to create objects from References.
*
@@ -332,7 +344,7 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
}
else
{
- throw new JMSException("The connection factory wasn't created with a proper URL, the connection details are empty");
+ throw new JMSException(NO_URL_CONFIGURED);
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
index 20496026ce..bb92fa4ecd 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
+++ b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
@@ -18,7 +18,9 @@
* under the License.
*
*/
-package org.apache.qpid.test.unit.jndi;
+package org.apache.qpid.client;
+
+import javax.jms.JMSException;
import junit.framework.TestCase;
@@ -26,7 +28,7 @@ import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionURL;
-public class ConnectionFactoryTest extends TestCase
+public class AMQConnectionFactoryTest extends TestCase
{
//URL will be returned with the password field swapped for '********'
@@ -58,6 +60,20 @@ public class ConnectionFactoryTest extends TestCase
assertEquals("tcp", service.getTransport());
assertEquals("localhost", service.getHost());
assertEquals(5672, service.getPort());
+ }
+
+ public void testInstanceCreatedWithDefaultConstructorThrowsExceptionOnCallingConnectWithoutSettingURL() throws Exception
+ {
+ AMQConnectionFactory factory = new AMQConnectionFactory();
+ try
+ {
+ factory.createConnection();
+ fail("Expected exception not thrown");
+ }
+ catch(JMSException e)
+ {
+ assertEquals("Unexpected exception", AMQConnectionFactory.NO_URL_CONFIGURED, e.getMessage());
+ }
}
}