ARTEMIS-1206 SetClientID from Core ConnectionFactory is not unique

This commit is contained in:
Clebert Suconic 2017-06-06 12:58:28 -04:00
parent 9d5d2d5344
commit 545414c18b
2 changed files with 45 additions and 7 deletions

View File

@ -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);

View File

@ -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();