JMX: Quote object name values if not identifiers

https://www.oracle.com/technetwork/java/javase/tech/best-practices-jsp-136021.html

The set of characters in a value is also limited. If special characters may
occur, it is recommended that the value be quoted, using ObjectName.quote. If
the value for a given key is sometimes quoted, then it should always be quoted.
By default, if a value is a string (rather than a number, say), then it should
be quoted unless you are sure that it will never contain special characters.

Practically, some special characters are allowed, but we will standardize on
allowed characters in java identifiers.
This commit is contained in:
Gary Russell
2018-10-09 14:56:31 -04:00
committed by Artem Bilan
parent 7ef38919b8
commit 551f03caa4
6 changed files with 44 additions and 12 deletions

View File

@@ -23,6 +23,8 @@
<si:channel id="channel"/>
<si:channel id="org.springframework.integration.test.anon"/>
<jmx:notification-publishing-channel-adapter
id="adapter" channel="channel"
object-name="test.publisher:name=publisher"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -139,8 +139,12 @@ public class NotificationPublishingChannelAdapterParserTests {
assertEquals("test.type", notification.getType());
assertNull(notification.getUserData());
Set<ObjectName> names = server
.queryNames(new ObjectName("*:type=MessageHandler," + "name=chainWithJmxNotificationPublishing$child."
+ "jmx-notification-publishing-channel-adapter-within-chain,*"), null);
.queryNames(new ObjectName("*:type=MessageHandler," + "name=\"chainWithJmxNotificationPublishing$child."
+ "jmx-notification-publishing-channel-adapter-within-chain\",*"), null);
assertEquals(1, names.size());
names = server
.queryNames(new ObjectName("*:type=MessageChannel,"
+ "name=org.springframework.integration.test.anon,source=anonymous,*"), null);
assertEquals(1, names.size());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class MessagingGatewaySupportRegistrationTests {
names = this.server.queryNames(new ObjectName("org.springframework.integration:*,type=MessageSource,name=foo"),
null);
assertEquals(1, names.size());
names = this.server.queryNames(new ObjectName("org.springframework.integration:*,name=foo#2"), null);
names = this.server.queryNames(new ObjectName("org.springframework.integration:*,name=\"foo#2\""), null);
assertEquals(1, names.size());
}