diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java index b8ed6e38f8..9f2d0bf842 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConnectionView.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.core.management.impl.view.predicate.ConnectionFilterPredicate; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ServerSession; @@ -51,10 +52,14 @@ public class ConnectionView extends ActiveMQAbstractView { List sessions = server.getSessions(connection.getID().toString()); Set users = new HashSet<>(); - + String jmsSessionClientID = null; for (ServerSession session : sessions) { String username = session.getUsername() == null ? "" : session.getUsername(); users.add(username); + //for the special case for JMS + if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) { + jmsSessionClientID = session.getMetaData("jms-client-id"); + } } return JsonLoader.createObjectBuilder().add("connectionID", toString(connection.getID())) @@ -63,7 +68,7 @@ public class ConnectionView extends ActiveMQAbstractView { .add("creationTime", new Date(connection.getCreationTime()).toString()) .add("implementation", toString(connection.getClass().getSimpleName())) .add("protocol", toString(connection.getProtocolName())) - .add("clientID", toString(connection.getClientID())) + .add("clientID", toString(connection.getClientID() != null ? connection.getClientID() : jmsSessionClientID)) .add("localAddress", toString(connection.getTransportLocalAddress())) .add("sessionCount", server.getSessions(connection.getID().toString()).size()); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java index b29be0992f..019e64b246 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ConsumerView.java @@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.management.impl.view; import javax.json.JsonObjectBuilder; import java.util.Date; +import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.core.management.impl.view.predicate.ConsumerFilterPredicate; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ServerConsumer; @@ -51,9 +52,15 @@ public class ConsumerView extends ActiveMQAbstractView { return null; } + String jmsSessionClientID = null; + //for the special case for JMS + if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) { + jmsSessionClientID = session.getMetaData("jms-client-id"); + } + JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(consumer.getSequentialID())) .add("session", toString(consumer.getSessionName())) - .add("clientID", toString(consumer.getConnectionClientID())) + .add("clientID", toString(consumer.getConnectionClientID() != null ? consumer.getConnectionClientID() : jmsSessionClientID)) .add("user", toString(session.getUsername())) .add("protocol", toString(consumer.getConnectionProtocolName())) .add("queue", toString(consumer.getQueueName())) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java index 977aec8169..27aed84a58 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/view/ProducerView.java @@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.management.impl.view; import javax.json.JsonObjectBuilder; +import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.core.management.impl.view.predicate.ProducerFilterPredicate; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ServerProducer; @@ -50,9 +51,15 @@ public class ProducerView extends ActiveMQAbstractView { return null; } + String jmsSessionClientID = null; + //for the special case for JMS + if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) { + jmsSessionClientID = session.getMetaData("jms-client-id"); + } + JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(producer.getID())) .add("session", toString(session.getName())) - .add("clientID", toString(session.getRemotingConnection().getClientID())) + .add("clientID", toString(session.getRemotingConnection().getClientID() != null ? session.getRemotingConnection().getClientID() : jmsSessionClientID)) .add("user", toString(session.getUsername())) .add("protocol", toString(session.getRemotingConnection().getProtocolName())) .add("address", toString(producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress())) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index 0e40041686..c74e6d55a3 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -86,6 +86,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static org.apache.activemq.artemis.jms.client.ActiveMQConnection.JMS_SESSION_CLIENT_ID_PROPERTY; + public class ActiveMQServerControlTest extends ManagementTestBase { // Constants ----------------------------------------------------- @@ -2470,6 +2472,44 @@ public class ActiveMQServerControlTest extends ManagementTestBase { } } + @Test + public void testListConnectionsClientID() throws Exception { + SimpleString queueName1 = new SimpleString("my_queue_one"); + SimpleString addressName1 = new SimpleString("my_address_one"); + + ActiveMQServerControl serverControl = createManagementControl(); + + server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST)); + server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false); + + ClientSessionFactoryImpl csf = null; + + // create some consumers + try (ServerLocator locator = createInVMNonHALocator()) { + //sleep as test compares creationTime + csf = (ClientSessionFactoryImpl) createSessionFactory(locator); + ClientSession session1_c1 = csf.createSession(); + ClientSession session2_c1 = csf.createSession(); + session1_c1.addMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY, ""); + session1_c1.addMetaData(JMS_SESSION_CLIENT_ID_PROPERTY, "MYClientID"); + + String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1"); + String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50); + JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString); + JsonArray array = (JsonArray) connectionsAsJsonObject.get("data"); + + Assert.assertEquals("number of connections returned from query", 1, array.size()); + JsonObject jsonConnection = array.getJsonObject(0); + + //check all fields + Assert.assertEquals("clientID", "MYClientID", jsonConnection.getString("clientID")); + } finally { + if (csf != null) { + csf.close(); + } + } + } + @Test public void testListProducers() throws Exception { SimpleString queueName1 = new SimpleString("my_queue_one");