mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-28 20:09:14 +08:00
This commit is contained in:
@@ -1065,6 +1065,7 @@ public class AdminBrokerProcessor implements NettyRequestProcessor {
|
||||
String content = this.brokerController.getConfiguration().getAllConfigsFormatString();
|
||||
if (content != null && content.length() > 0) {
|
||||
try {
|
||||
content = MixAll.adjustConfigForPlatform(content);
|
||||
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOGGER.error("AdminBrokerProcessor#getBrokerConfig: unexpected error, caller={}",
|
||||
|
||||
@@ -557,4 +557,13 @@ public class MixAll {
|
||||
&& !topic.startsWith(TopicValidator.SYSTEM_TOPIC_PREFIX)
|
||||
&& !topic.equals(TopicValidator.RMQ_SYS_SCHEDULE_TOPIC);
|
||||
}
|
||||
|
||||
public static String adjustConfigForPlatform(String config) {
|
||||
if (StringUtils.isNotBlank(config)) {
|
||||
if (isWindows()) {
|
||||
config = StringUtils.replace(config, "\\", "\\\\");
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,4 +85,43 @@ public class MixAllTest {
|
||||
testLmq = "%LMQ%GID_TEST";
|
||||
assertThat(MixAll.isLmq(testLmq)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdjustConfigForPlatform_OnWindows() {
|
||||
if (MixAll.isWindows()) {
|
||||
String configWithSingleBackslash = "data\\path\\config\\file.properties";
|
||||
String adjusted = MixAll.adjustConfigForPlatform(configWithSingleBackslash);
|
||||
assertThat(adjusted).isEqualTo("data\\\\path\\\\config\\\\file.properties");
|
||||
|
||||
String configWithMultipleBackslashes = "C:\\\\RocketMQ\\\\logs\\\\broker.log";
|
||||
adjusted = MixAll.adjustConfigForPlatform(configWithMultipleBackslashes);
|
||||
assertThat(adjusted).isEqualTo("C:\\\\\\\\RocketMQ\\\\\\\\logs\\\\\\\\broker.log");
|
||||
|
||||
String configWithoutBackslash = "listenPort=10911";
|
||||
adjusted = MixAll.adjustConfigForPlatform(configWithoutBackslash);
|
||||
assertThat(adjusted).isEqualTo("listenPort=10911");
|
||||
|
||||
String emptyConfig = "";
|
||||
adjusted = MixAll.adjustConfigForPlatform(emptyConfig);
|
||||
assertThat(adjusted).isEqualTo("");
|
||||
|
||||
adjusted = MixAll.adjustConfigForPlatform(null);
|
||||
assertThat(adjusted).isNull();
|
||||
} else {
|
||||
String configWithSingleBackslash = "/home/rocketmq/conf/broker.conf";
|
||||
String adjusted = MixAll.adjustConfigForPlatform(configWithSingleBackslash);
|
||||
assertThat(adjusted).isEqualTo("/home/rocketmq/conf/broker.conf");
|
||||
|
||||
String linuxPathWithBackslash = "some\\directory\\file.txt";
|
||||
adjusted = MixAll.adjustConfigForPlatform(linuxPathWithBackslash);
|
||||
assertThat(adjusted).isEqualTo("some\\directory\\file.txt");
|
||||
|
||||
String emptyConfig = "";
|
||||
adjusted = MixAll.adjustConfigForPlatform(emptyConfig);
|
||||
assertThat(adjusted).isEqualTo("");
|
||||
|
||||
adjusted = MixAll.adjustConfigForPlatform(null);
|
||||
assertThat(adjusted).isNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +291,7 @@ public class BrokerContainerProcessor implements NettyRequestProcessor {
|
||||
String content = this.brokerContainer.getConfiguration().getAllConfigsFormatString();
|
||||
if (content != null && content.length() > 0) {
|
||||
try {
|
||||
content = MixAll.adjustConfigForPlatform(content);
|
||||
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOGGER.error("", e);
|
||||
|
||||
+1
@@ -311,6 +311,7 @@ public class ControllerRequestProcessor implements NettyRequestProcessor {
|
||||
String content = this.controllerManager.getConfiguration().getAllConfigsFormatString();
|
||||
if (content != null && content.length() > 0) {
|
||||
try {
|
||||
content = MixAll.adjustConfigForPlatform(content);
|
||||
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("getConfig error, ", e);
|
||||
|
||||
+1
@@ -658,6 +658,7 @@ public class DefaultRequestProcessor implements NettyRequestProcessor {
|
||||
String content = this.namesrvController.getConfiguration().getAllConfigsFormatString();
|
||||
if (StringUtils.isNotBlank(content)) {
|
||||
try {
|
||||
content = MixAll.adjustConfigForPlatform(content);
|
||||
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("getConfig error, ", e);
|
||||
|
||||
Reference in New Issue
Block a user