This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 797f27bd99 ARTEMIS-5347 support environment variable substitution in
bootstrap.xml
797f27bd99 is described below
commit 797f27bd99dcc415c8e278dcf8a9635594ea0799
Author: Justin Bertram <[email protected]>
AuthorDate: Tue Mar 11 14:41:11 2025 -0500
ARTEMIS-5347 support environment variable substitution in bootstrap.xml
---
.../org/apache/activemq/artemis/dto/XmlUtil.java | 1 +
.../apache/activemq/artemis/dto/XmlUtilTest.java | 55 ++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git
a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
index 5bcfb0216b..60f9bfe4ea 100644
--- a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
+++ b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/XmlUtil.java
@@ -95,6 +95,7 @@ public class XmlUtil {
unmarshaller.setSchema(schema);
Properties props = new Properties(System.getProperties());
+ props.putAll(System.getenv());
if (artemisHome != null) {
props.put("artemis.home", artemisHome);
}
diff --git
a/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java
b/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java
new file mode 100644
index 0000000000..b629ba02d7
--- /dev/null
+++ b/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.dto;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class XmlUtilTest {
+
+ @Test
+ public void testPropertySubstituion(@TempDir Path tempDir) throws Exception
{
+ final String SYSTEM_PROP_NAME = "sysPropName";
+ final String SYSTEM_PROP_VALUE = "sysPropValue";
+ System.setProperty(SYSTEM_PROP_NAME, SYSTEM_PROP_VALUE);
+
+ // since System.getenv() returns an immutable Map we rely here on an
environment variable that is likely to exist
+ final String ENV_VAR_NAME = "HOME";
+
+ String data = """
+ <broker xmlns="http://activemq.apache.org/schema">
+ <jaas-security domain="${%s}"/>
+ <server configuration="${%s}"/>
+ </broker>
+ """.formatted(SYSTEM_PROP_NAME, ENV_VAR_NAME);
+
+ Path tempFile = Files.createTempFile(tempDir, "testBootstrap", ".xml");
+ Files.write(tempFile, data.getBytes(), StandardOpenOption.WRITE);
+ assertTrue(Files.exists(tempFile));
+
+ BrokerDTO brokerDTO = XmlUtil.decode(BrokerDTO.class, tempFile.toFile());
+ assertEquals(SYSTEM_PROP_VALUE,
((JaasSecurityDTO)brokerDTO.security).domain);
+ assertEquals(System.getenv(ENV_VAR_NAME),
brokerDTO.server.configuration);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact