@Test public void testConfigurationsLoadedFromMultipleFilesForDefaultServerWithAbsolutePath() { String config = this.getClass().getClassLoader().getResource("servers/default").getPath(); Configuration configuration = factory.initConfiguration(config, "default", "dummy", null); assertEquals("blue", configuration.get("test.blue")); assertEquals("red", configuration.get("test.red")); assertNull(configuration.get("test.green")); assertEquals("bluevaluefromuser", configuration.get("test.blue.key")); assertEquals("redvaluefromuser", configuration.get("test.red.key")); assertEquals("uservalue", configuration.get("test.user.key")); }
@Override public Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties) { LOG.debug("Initializing configuration for server {}", serverName); Configuration configuration = new Configuration(); configuration.set(CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, "true"); configuration.set(PXF_SESSION_USER_PROPERTY, userName); File[] serverDirectories = null; Path p = Paths.get(configDirectory); if (p.isAbsolute()) { File f = p.toFile(); if (f.exists() && f.isDirectory() && f.canRead()) { serverDirectories = new File[]{f}; } } else { serverDirectories = serversConfigDirectory .listFiles(f -> f.isDirectory() && f.canRead() && StringUtils.equalsIgnoreCase(configDirectory, f.getName())); } if (ArrayUtils.isEmpty(serverDirectories)) { LOG.debug("Directory {}{}{} does not exist or cannot be read by PXF, no configuration resources are added for server {}", serversConfigDirectory, File.separator, configDirectory, serverName); } else if (serverDirectories.length > 1) { throw new IllegalStateException(String.format( "Multiple directories found for server %s. Server directories are expected to be case-insensitive.", serverName )); } else { LOG.debug("Using directory {} for server {} configuration", serverDirectories[0], serverName); processServerResources(configuration, serverName, serverDirectories[0]); } if (additionalProperties != null) { LOG.debug("Adding {} additional properties to configuration for server {}", additionalProperties.size(), serverName); additionalProperties.forEach(configuration::set); } if (!ArrayUtils.isEmpty(serverDirectories)) { processUserResource(configuration, serverName, userName, serverDirectories[0]); } try { configuration.setRestrictSystemProps(false); } catch (NoSuchMethodError e) { } return configuration; }
BaseConfigurationFactory implements ConfigurationFactory { @Override public Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties) { LOG.debug("Initializing configuration for server {}", serverName); Configuration configuration = new Configuration(); configuration.set(CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, "true"); configuration.set(PXF_SESSION_USER_PROPERTY, userName); File[] serverDirectories = null; Path p = Paths.get(configDirectory); if (p.isAbsolute()) { File f = p.toFile(); if (f.exists() && f.isDirectory() && f.canRead()) { serverDirectories = new File[]{f}; } } else { serverDirectories = serversConfigDirectory .listFiles(f -> f.isDirectory() && f.canRead() && StringUtils.equalsIgnoreCase(configDirectory, f.getName())); } if (ArrayUtils.isEmpty(serverDirectories)) { LOG.debug("Directory {}{}{} does not exist or cannot be read by PXF, no configuration resources are added for server {}", serversConfigDirectory, File.separator, configDirectory, serverName); } else if (serverDirectories.length > 1) { throw new IllegalStateException(String.format( "Multiple directories found for server %s. Server directories are expected to be case-insensitive.", serverName )); } else { LOG.debug("Using directory {} for server {} configuration", serverDirectories[0], serverName); processServerResources(configuration, serverName, serverDirectories[0]); } if (additionalProperties != null) { LOG.debug("Adding {} additional properties to configuration for server {}", additionalProperties.size(), serverName); additionalProperties.forEach(configuration::set); } if (!ArrayUtils.isEmpty(serverDirectories)) { processUserResource(configuration, serverName, userName, serverDirectories[0]); } try { configuration.setRestrictSystemProps(false); } catch (NoSuchMethodError e) { } return configuration; } }
BaseConfigurationFactory implements ConfigurationFactory { @Override public Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties) { LOG.debug("Initializing configuration for server {}", serverName); Configuration configuration = new Configuration(); configuration.set(CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, "true"); configuration.set(PXF_SESSION_USER_PROPERTY, userName); File[] serverDirectories = null; Path p = Paths.get(configDirectory); if (p.isAbsolute()) { File f = p.toFile(); if (f.exists() && f.isDirectory() && f.canRead()) { serverDirectories = new File[]{f}; } } else { serverDirectories = serversConfigDirectory .listFiles(f -> f.isDirectory() && f.canRead() && StringUtils.equalsIgnoreCase(configDirectory, f.getName())); } if (ArrayUtils.isEmpty(serverDirectories)) { LOG.debug("Directory {}{}{} does not exist or cannot be read by PXF, no configuration resources are added for server {}", serversConfigDirectory, File.separator, configDirectory, serverName); } else if (serverDirectories.length > 1) { throw new IllegalStateException(String.format( "Multiple directories found for server %s. Server directories are expected to be case-insensitive.", serverName )); } else { LOG.debug("Using directory {} for server {} configuration", serverDirectories[0], serverName); processServerResources(configuration, serverName, serverDirectories[0]); } if (additionalProperties != null) { LOG.debug("Adding {} additional properties to configuration for server {}", additionalProperties.size(), serverName); additionalProperties.forEach(configuration::set); } if (!ArrayUtils.isEmpty(serverDirectories)) { processUserResource(configuration, serverName, userName, serverDirectories[0]); } try { configuration.setRestrictSystemProps(false); } catch (NoSuchMethodError e) { } return configuration; } BaseConfigurationFactory();   BaseConfigurationFactory(File serversConfigDirectory); }
BaseConfigurationFactory implements ConfigurationFactory { @Override public Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties) { LOG.debug("Initializing configuration for server {}", serverName); Configuration configuration = new Configuration(); configuration.set(CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, "true"); configuration.set(PXF_SESSION_USER_PROPERTY, userName); File[] serverDirectories = null; Path p = Paths.get(configDirectory); if (p.isAbsolute()) { File f = p.toFile(); if (f.exists() && f.isDirectory() && f.canRead()) { serverDirectories = new File[]{f}; } } else { serverDirectories = serversConfigDirectory .listFiles(f -> f.isDirectory() && f.canRead() && StringUtils.equalsIgnoreCase(configDirectory, f.getName())); } if (ArrayUtils.isEmpty(serverDirectories)) { LOG.debug("Directory {}{}{} does not exist or cannot be read by PXF, no configuration resources are added for server {}", serversConfigDirectory, File.separator, configDirectory, serverName); } else if (serverDirectories.length > 1) { throw new IllegalStateException(String.format( "Multiple directories found for server %s. Server directories are expected to be case-insensitive.", serverName )); } else { LOG.debug("Using directory {} for server {} configuration", serverDirectories[0], serverName); processServerResources(configuration, serverName, serverDirectories[0]); } if (additionalProperties != null) { LOG.debug("Adding {} additional properties to configuration for server {}", additionalProperties.size(), serverName); additionalProperties.forEach(configuration::set); } if (!ArrayUtils.isEmpty(serverDirectories)) { processUserResource(configuration, serverName, userName, serverDirectories[0]); } try { configuration.setRestrictSystemProps(false); } catch (NoSuchMethodError e) { } return configuration; } BaseConfigurationFactory();   BaseConfigurationFactory(File serversConfigDirectory); static BaseConfigurationFactory getInstance(); @Override Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties); }
BaseConfigurationFactory implements ConfigurationFactory { @Override public Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties) { LOG.debug("Initializing configuration for server {}", serverName); Configuration configuration = new Configuration(); configuration.set(CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY, "true"); configuration.set(PXF_SESSION_USER_PROPERTY, userName); File[] serverDirectories = null; Path p = Paths.get(configDirectory); if (p.isAbsolute()) { File f = p.toFile(); if (f.exists() && f.isDirectory() && f.canRead()) { serverDirectories = new File[]{f}; } } else { serverDirectories = serversConfigDirectory .listFiles(f -> f.isDirectory() && f.canRead() && StringUtils.equalsIgnoreCase(configDirectory, f.getName())); } if (ArrayUtils.isEmpty(serverDirectories)) { LOG.debug("Directory {}{}{} does not exist or cannot be read by PXF, no configuration resources are added for server {}", serversConfigDirectory, File.separator, configDirectory, serverName); } else if (serverDirectories.length > 1) { throw new IllegalStateException(String.format( "Multiple directories found for server %s. Server directories are expected to be case-insensitive.", serverName )); } else { LOG.debug("Using directory {} for server {} configuration", serverDirectories[0], serverName); processServerResources(configuration, serverName, serverDirectories[0]); } if (additionalProperties != null) { LOG.debug("Adding {} additional properties to configuration for server {}", additionalProperties.size(), serverName); additionalProperties.forEach(configuration::set); } if (!ArrayUtils.isEmpty(serverDirectories)) { processUserResource(configuration, serverName, userName, serverDirectories[0]); } try { configuration.setRestrictSystemProps(false); } catch (NoSuchMethodError e) { } return configuration; } BaseConfigurationFactory();   BaseConfigurationFactory(File serversConfigDirectory); static BaseConfigurationFactory getInstance(); @Override Configuration initConfiguration(String configDirectory, String serverName, String userName, Map<String, String> additionalProperties);  }