This closes #1321
This commit is contained in:
commit
25e9fd78d3
|
@ -242,13 +242,7 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme
|
|||
throw new IllegalStateException("setClientID can only be called directly after the connection is created");
|
||||
}
|
||||
|
||||
try {
|
||||
initialSession.addUniqueMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientID);
|
||||
} catch (ActiveMQException e) {
|
||||
if (e.getType() == ActiveMQExceptionType.DUPLICATE_METADATA) {
|
||||
throw new InvalidClientIDException("clientID=" + clientID + " was already set into another connection");
|
||||
}
|
||||
}
|
||||
validateClientID(initialSession, clientID);
|
||||
|
||||
this.clientID = clientID;
|
||||
try {
|
||||
|
@ -263,6 +257,16 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme
|
|||
justCreated = false;
|
||||
}
|
||||
|
||||
private void validateClientID(ClientSession validateSession, String clientID) throws InvalidClientIDException {
|
||||
try {
|
||||
validateSession.addUniqueMetaData(ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY, clientID);
|
||||
} catch (ActiveMQException e) {
|
||||
if (e.getType() == ActiveMQExceptionType.DUPLICATE_METADATA) {
|
||||
throw new InvalidClientIDException("clientID=" + clientID + " was already set into another connection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionMetaData getMetaData() throws JMSException {
|
||||
checkClosed();
|
||||
|
@ -669,6 +673,10 @@ public class ActiveMQConnection extends ActiveMQConnectionForContextImpl impleme
|
|||
try {
|
||||
initialSession = sessionFactory.createSession(username, password, false, false, false, false, 0);
|
||||
|
||||
if (clientID != null) {
|
||||
validateClientID(initialSession, clientID);
|
||||
}
|
||||
|
||||
addSessionMetaData(initialSession);
|
||||
|
||||
initialSession.addFailureListener(listener);
|
||||
|
|
|
@ -100,8 +100,38 @@ public class ConnectionTest extends JMSTestBase {
|
|||
} catch (InvalidClientIDException expected) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
||||
Session session1 = conn.createSession();
|
||||
Session session2 = conn.createSession();
|
||||
|
||||
session1.close();
|
||||
session2.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTwoConnectionsSameIDThroughCF() throws Exception {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid");
|
||||
|
||||
conn = connectionFactory.createConnection();
|
||||
try {
|
||||
conn2 = connectionFactory.createConnection();
|
||||
Assert.fail("Exception expected");
|
||||
} catch (InvalidClientIDException expected) {
|
||||
// expected
|
||||
}
|
||||
|
||||
|
||||
Session session1 = conn.createSession();
|
||||
Session session2 = conn.createSession();
|
||||
|
||||
session1.close();
|
||||
session2.close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetSetConnectionFactory() throws Exception {
|
||||
conn = cf.createConnection();
|
||||
|
|
Loading…
Reference in New Issue