From 73b471ccfc1be11728ed4495412cc83718bfc0f2 Mon Sep 17 00:00:00 2001 From: Alexander Skoblikov Date: Thu, 23 Jun 2022 16:04:18 +0300 Subject: [PATCH] CB-2133 read external configuration if runtime.conf not exist --- .../io/cloudbeaver/server/CBApplication.java | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index e6349c6667..5009abc2e0 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -599,30 +599,39 @@ public class CBApplication extends BaseWebApplication { } protected Map readConfiguration(File configFile) throws DBException { - try (Reader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { - Map configProps = JSONUtils.parseMap(getGson(), reader); - patchConfigurationWithProperties(configProps); // patch original properties - readAdditionalConfiguration(configProps); - Map serverConfig = getServerConfigProps(configProps); + Map configProps = new LinkedHashMap<>(); + if (configFile.exists()) { + log.debug("Read configuration [" + configFile.getAbsolutePath() + "]"); + try (Reader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { + configProps.putAll(JSONUtils.parseMap(getGson(), reader)); + patchConfigurationWithProperties(configProps); // patch original properties - String externalPropertiesFile = JSONUtils.getString(serverConfig, CBConstants.PARAM_EXTERNAL_PROPERTIES); - if (!CommonUtils.isEmpty(externalPropertiesFile)) { - Properties props = new Properties(); - try (InputStream is = Files.newInputStream(Path.of(externalPropertiesFile))) { - props.load(is); - } catch (IOException e) { - log.error("Error loading external properties from " + externalPropertiesFile, e); - } - for (String propName : props.stringPropertyNames()) { - this.externalProperties.put(propName, props.getProperty(propName)); - } + } catch (IOException e) { + throw new DBException("Error parsing server configuration", e); } - - patchConfigurationWithProperties(configProps); // patch again because properties can be changed - return configProps; - } catch (IOException e) { - throw new DBException("Error parsing server configuration", e); } + + readAdditionalConfiguration(configProps); + if (configProps.isEmpty()) { + return Map.of(); + } + + Map serverConfig = getServerConfigProps(configProps); + String externalPropertiesFile = JSONUtils.getString(serverConfig, CBConstants.PARAM_EXTERNAL_PROPERTIES); + if (!CommonUtils.isEmpty(externalPropertiesFile)) { + Properties props = new Properties(); + try (InputStream is = Files.newInputStream(Path.of(externalPropertiesFile))) { + props.load(is); + } catch (IOException e) { + log.error("Error loading external properties from " + externalPropertiesFile, e); + } + for (String propName : props.stringPropertyNames()) { + this.externalProperties.put(propName, props.getProperty(propName)); + } + } + + patchConfigurationWithProperties(configProps); // patch again because properties can be changed + return configProps; } private Gson getGson() { @@ -736,11 +745,7 @@ public class CBApplication extends BaseWebApplication { private Map readRuntimeConfigurationProperties() throws DBException { File runtimeConfigFile = getRuntimeAppConfigFile(); - if (runtimeConfigFile.exists()) { - log.debug("Runtime configuration [" + runtimeConfigFile.getAbsolutePath() + "]"); - return readConfiguration(runtimeConfigFile); - } - return Map.of(); + return readConfiguration(runtimeConfigFile); } protected void finishSecurityServiceConfiguration(@NotNull String adminName, @Nullable String adminPassword, @NotNull List authInfoList) throws DBException {