You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by ha...@apache.org on 2026/10/12 14:02:04 UTC
(knox) branch master updated: KNOX-3511: Gateway ignores gateway-reloadable.xml if the file did not exist at startup (#1450)
This is an automated email from the ASF dual-hosted git repository.
hanicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new 30a18b4e0 KNOX-3511: Gateway ignores gateway-reloadable.xml if the file did not exist at startup (#1450)
30a18b4e0 is described below
commit 30a18b4e029198241a39e36534110c23d5d25568
Author: hanicz <ha...@users.noreply.github.com>
AuthorDate: Mon Oct 12 16:01:58 2026 +0200
KNOX-3511: Gateway ignores gateway-reloadable.xml if the file did not exist at startup (#1450)
---
.../org/apache/knox/gateway/GatewayServer.java | 1 +
.../gateway/config/impl/GatewayConfigImpl.java | 11 ++++++
.../org/apache/knox/gateway/GatewayServerTest.java | 2 ++
.../gateway/config/impl/GatewayConfigImplTest.java | 39 ++++++++++++++++++++++
4 files changed, 53 insertions(+)
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
index 23b35e95b..405604f63 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
@@ -273,6 +273,7 @@ public class GatewayServer {
FileTime lastModifiedTime = Files.getLastModifiedTime(resourcePath);
if (lastReloadTime == null || lastReloadTime.compareTo(lastModifiedTime) < 0) {
lastReloadTime = lastModifiedTime;
+ config.addConfigFileIfAbsent(resourcePath.toFile());
config.reloadConfiguration();
log.refreshedGatewayConfig();
for (GatewayConfigChangeListener listener : configChangeListeners) {
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index deb5213b9..a9ddbaf33 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -96,6 +96,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
private static final GatewayMessages log = MessagesFactory.get( GatewayMessages.class );
+ private final Set<String> registeredConfigFiles = new HashSet<>();
+
private static final String GATEWAY_CONFIG_DIR_PREFIX = "conf";
private static final String GATEWAY_CONFIG_FILE_PREFIX = "gateway";
@@ -563,6 +565,7 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
try {
url = f.toURI().toURL();
addResource( new Path( path ) );
+ registeredConfigFiles.add( path );
log.loadingConfigurationFile( path );
} catch ( MalformedURLException e ) {
log.failedToLoadConfig( path, e );
@@ -572,6 +575,14 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
return url;
}
+ public synchronized void addConfigFileIfAbsent( File file ) {
+ String path = file.getAbsolutePath();
+ if( file.exists() && registeredConfigFiles.add( path ) ) {
+ addResource( new Path( path ) );
+ log.loadingConfigurationFile( path );
+ }
+ }
+
private URL loadConfigResource( String file ) {
URL url = getResource( file );
if( url != null ) {
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/GatewayServerTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/GatewayServerTest.java
index 4ad86d326..e8ad52e9c 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/GatewayServerTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/GatewayServerTest.java
@@ -69,6 +69,8 @@ public class GatewayServerTest {
lastReloadTimeField.set(null, null);
// Initial load
+ config.addConfigFileIfAbsent(configFile);
+ EasyMock.expectLastCall().once();
config.reloadConfiguration();
EasyMock.expectLastCall().once();
EasyMock.replay(config);
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
index 9a337146b..c93d2279b 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
@@ -822,11 +822,50 @@ public class GatewayConfigImplTest {
System.setProperty("KNOX_GATEWAY_CONF_DIR", dir.getAbsolutePath());
GatewayConfigImpl config = new GatewayConfigImpl();
assertThat(config.get("test.reloadable.prop"), is("test.reloadable.val"));
+
+ config.addConfigFileIfAbsent(reloadableFile);
+ config.reloadConfiguration();
+ assertThat(config.get("test.reloadable.prop"), is("test.reloadable.val"));
} finally {
System.clearProperty("KNOX_GATEWAY_CONF_DIR");
}
}
+ @Test
+ public void testReloadableConfigCreatedAfterStartupIsLoaded() throws Exception {
+ File dir = folder.newFolder("conf");
+ File reloadableFile = new File(dir, "gateway-reloadable.xml");
+
+ try {
+ System.setProperty("KNOX_GATEWAY_CONF_DIR", dir.getAbsolutePath());
+ GatewayConfigImpl config = new GatewayConfigImpl();
+ assertThat(config.get("test.reloadable.prop"), nullValue());
+
+ writeReloadableConfig(reloadableFile, "test.reloadable.val");
+ config.addConfigFileIfAbsent(reloadableFile);
+ config.reloadConfiguration();
+ assertThat(config.get("test.reloadable.prop"), is("test.reloadable.val"));
+
+ writeReloadableConfig(reloadableFile, "test.reloadable.val2");
+ config.addConfigFileIfAbsent(reloadableFile);
+ config.reloadConfiguration();
+ assertThat(config.get("test.reloadable.prop"), is("test.reloadable.val2"));
+ } finally {
+ System.clearProperty("KNOX_GATEWAY_CONF_DIR");
+ }
+ }
+
+ private static void writeReloadableConfig(File file, String value) throws Exception {
+ try (PrintWriter writer = new PrintWriter(file, StandardCharsets.UTF_8)) {
+ writer.println("<configuration>");
+ writer.println(" <property>");
+ writer.println(" <name>test.reloadable.prop</name>");
+ writer.println(" <value>" + value + "</value>");
+ writer.println(" </property>");
+ writer.println("</configuration>");
+ }
+ }
+
@Test
public void testSigningKeyAliases() {
GatewayConfigImpl config = new GatewayConfigImpl();