Author: robbie
Date: Mon May 28 12:20:35 2012
New Revision: 1343220
URL: http://svn.apache.org/viewvc?rev=1343220&view=rev
Log:
QPID-4023: restore connection URL setter, add check that URL details have been
set before calling connect(), add unit+sys test to verify operation
Added:
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
- copied, changed from r1342886,
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
Removed:
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
Modified:
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java
Modified:
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java?rev=1343220&r1=1343219&r2=1343220&view=diff
==============================================================================
---
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
(original)
+++
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
Mon May 28 12:20:35 2012
@@ -55,12 +55,13 @@ public class AMQConnectionFactory implem
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 implem
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 implem
}
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 implem
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 implem
}
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);
}
}
Copied:
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
(from r1342886,
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java)
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java?p2=qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java&p1=qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java&r1=1342886&r2=1343220&rev=1343220&view=diff
==============================================================================
---
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
(original)
+++
qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
Mon May 28 12:20:35 2012
@@ -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.AMQConnect
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 exten
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());
+ }
}
}
Modified:
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java?rev=1343220&r1=1343219&r2=1343220&view=diff
==============================================================================
---
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java
(original)
+++
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java
Mon May 28 12:20:35 2012
@@ -20,6 +20,8 @@
*/
package org.apache.qpid.test.unit.client.connection;
+import javax.jms.Connection;
+
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.test.utils.QpidBrokerTestCase;
@@ -57,5 +59,20 @@ public class ConnectionFactoryTest exten
assertEquals("Usernames used is different from the one in
URL","guest",con3.getConnectionURL().getUsername());
assertEquals("Password used is different from the one in
URL","guest",con3.getConnectionURL().getPassword());
}
-
+
+ /**
+ * Verifies that a connection can be made using an instance of
AMQConnectionFactory created with the
+ * default constructor and provided with the connection url via setter.
+ */
+ public void
testCreatingConnectionWithInstanceMadeUsingDefaultConstructor() throws Exception
+ {
+ String broker = getBroker().toString();
+ String url = "amqp://guest:guest@clientID/test?brokerlist='" + broker
+ "'";
+
+ AMQConnectionFactory factory = new AMQConnectionFactory();
+ factory.setConnectionURLString(url);
+
+ Connection con = factory.createConnection();
+ con.close();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]