Skip to content

Commit d9d321e

Browse files
thezbygjbonofre
authored andcommitted
[AMQ-9768] Fix JMX value escaping in web console. (#1487)
(cherry picked from commit f68fff9)
1 parent dabbb6d commit d9d321e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

activemq-web/src/main/java/org/apache/activemq/web/BrokerFacadeSupport.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
import org.apache.activemq.broker.jmx.QueueViewMBean;
4343
import org.apache.activemq.broker.jmx.SubscriptionViewMBean;
4444
import org.apache.activemq.broker.jmx.TopicViewMBean;
45+
import org.apache.activemq.util.JMXSupport;
4546
import org.apache.activemq.web.util.ExceptionUtils;
46-
import org.springframework.util.StringUtils;
4747

4848
/**
4949
* A useful base class for an implementation of {@link BrokerFacade}
@@ -78,7 +78,7 @@ public Collection<TopicViewMBean> getTopics() throws Exception {
7878
@Override
7979
public Collection<SubscriptionViewMBean> getTopicSubscribers(String topicName) throws Exception {
8080
String brokerName = getBrokerName();
81-
topicName = StringUtils.replace(topicName, "\"", "_");
81+
topicName = JMXSupport.encodeObjectNamePart(topicName);
8282
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
8383
+ ",destinationType=Topic,destinationName=" + topicName + ",endpoint=Consumer,*");
8484
Set<ObjectName> queryResult = queryNames(query, null);
@@ -171,20 +171,22 @@ public Collection<ConnectionViewMBean> getConnections() throws Exception {
171171
@SuppressWarnings("unchecked")
172172
public Collection<String> getConnections(String connectorName) throws Exception {
173173
String brokerName = getBrokerName();
174+
connectorName = JMXSupport.encodeObjectNamePart(connectorName);
174175
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
175-
+ ",connector=clientConnectors,connectorName=" + connectorName + ",connectionViewType=clientId" + ",connectionName=*"); Set<ObjectName> queryResult = queryNames(query, null);
176+
+ ",connector=clientConnectors,connectorName=" + connectorName + ",connectionViewType=clientId,connectionName=*");
177+
Set<ObjectName> queryResult = queryNames(query, null);
178+
Collection<ConnectionViewMBean> connections = getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]),
179+
ConnectionViewMBean.class);
176180
Collection<String> result = new ArrayList<String>(queryResult.size());
177-
for (ObjectName on : queryResult) {
178-
String name = StringUtils.replace(on.getKeyProperty("connectionName"), "_", ":");
179-
result.add(name);
180-
}
181+
for (ConnectionViewMBean connection : connections)
182+
result.add(connection.getClientId());
181183
return result;
182184
}
183185

184186
@Override
185187
@SuppressWarnings("unchecked")
186188
public ConnectionViewMBean getConnection(String connectionName) throws Exception {
187-
connectionName = StringUtils.replace(connectionName, ":", "_");
189+
connectionName = JMXSupport.encodeObjectNamePart(connectionName);
188190
String brokerName = getBrokerName();
189191
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
190192
+ ",connector=clientConnectors,*,connectionName=" + connectionName);
@@ -211,6 +213,7 @@ public Collection<String> getConnectors() throws Exception {
211213
@Override
212214
public ConnectorViewMBean getConnector(String name) throws Exception {
213215
String brokerName = getBrokerName();
216+
name = JMXSupport.encodeObjectNamePart(name);
214217
ObjectName objectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
215218
+ ",connector=clientConnectors,connectorName=" + name);
216219
return (ConnectorViewMBean) newProxyInstance(objectName, ConnectorViewMBean.class, true);
@@ -239,8 +242,7 @@ public Collection<NetworkBridgeViewMBean> getNetworkBridges() throws Exception {
239242
@SuppressWarnings("unchecked")
240243
public Collection<SubscriptionViewMBean> getQueueConsumers(String queueName) throws Exception {
241244
String brokerName = getBrokerName();
242-
queueName = StringUtils.replace(queueName, "\"", "_");
243-
queueName = StringUtils.replace(queueName, ":", "_");
245+
queueName = JMXSupport.encodeObjectNamePart(queueName);
244246
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
245247
+ ",destinationType=Queue,destinationName=" + queueName + ",endpoint=Consumer,*");
246248
Set<ObjectName> queryResult = queryNames(query, null);
@@ -251,8 +253,7 @@ public Collection<SubscriptionViewMBean> getQueueConsumers(String queueName) thr
251253
@SuppressWarnings("unchecked")
252254
public Collection<ProducerViewMBean> getQueueProducers(String queueName) throws Exception {
253255
String brokerName = getBrokerName();
254-
queueName = StringUtils.replace(queueName, "\"", "_");
255-
queueName = StringUtils.replace(queueName, ":", "_");
256+
queueName = JMXSupport.encodeObjectNamePart(queueName);
256257
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
257258
+ ",destinationType=Queue,destinationName=" + queueName + ",endpoint=Producer,*");
258259
Set<ObjectName> queryResult = queryNames(query, null);
@@ -263,8 +264,7 @@ public Collection<ProducerViewMBean> getQueueProducers(String queueName) throws
263264
@SuppressWarnings("unchecked")
264265
public Collection<ProducerViewMBean> getTopicProducers(String topicName) throws Exception {
265266
String brokerName = getBrokerName();
266-
topicName = StringUtils.replace(topicName, "\"", "_");
267-
topicName = StringUtils.replace(topicName, ":", "_");
267+
topicName = JMXSupport.encodeObjectNamePart(topicName);
268268
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
269269
+ ",destinationType=Topic,destinationName=" + topicName + ",endpoint=Producer,*");
270270
Set<ObjectName> queryResult = queryNames(query, null);
@@ -274,7 +274,7 @@ public Collection<ProducerViewMBean> getTopicProducers(String topicName) throws
274274
@Override
275275
@SuppressWarnings("unchecked")
276276
public Collection<SubscriptionViewMBean> getConsumersOnConnection(String connectionName) throws Exception {
277-
connectionName = StringUtils.replace(connectionName, ":", "_");
277+
connectionName = JMXSupport.encodeObjectNamePart(connectionName);
278278
String brokerName = getBrokerName();
279279
ObjectName query = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + brokerName
280280
+ ",*,endpoint=Consumer,clientId=" + connectionName);

0 commit comments

Comments
 (0)