Search in sources :

Example 6 with FileConfiguration

use of org.apache.commons.configuration.FileConfiguration in project distributedlog by twitter.

the class ConfigurationSubscription method reload.

@VisibleForTesting
void reload() {
    // No-op if already loaded.
    if (!initConfig()) {
        return;
    }
    // Reload if config exists.
    Set<String> confKeys = Sets.newHashSet();
    for (FileConfiguration fileConfig : fileConfigs) {
        LOG.debug("Check and reload config, file={}, lastModified={}", fileConfig.getFile(), fileConfig.getFile().lastModified());
        fileConfig.reload();
        // load keys
        Iterator keyIter = fileConfig.getKeys();
        while (keyIter.hasNext()) {
            String key = (String) keyIter.next();
            confKeys.add(key);
        }
    }
    // clear unexisted keys
    Iterator viewIter = viewConfig.getKeys();
    while (viewIter.hasNext()) {
        String key = (String) viewIter.next();
        if (!confKeys.contains(key)) {
            clearViewProperty(key);
        }
    }
    LOG.info("Reload features : {}", confKeys);
    // load keys from files
    for (FileConfiguration fileConfig : fileConfigs) {
        try {
            loadView(fileConfig);
        } catch (Exception ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config reload failed for file {}", fileConfig.getFileName(), ex);
            }
        }
    }
    for (ConfigurationListener listener : confListeners) {
        listener.onReload(viewConfig);
    }
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) Iterator(java.util.Iterator) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with FileConfiguration

use of org.apache.commons.configuration.FileConfiguration in project distributedlog by twitter.

the class ConfigurationSubscription method initConfig.

private boolean initConfig() {
    if (fileConfigs.isEmpty()) {
        try {
            for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) {
                FileConfiguration fileConfig = fileConfigBuilder.getConfiguration();
                FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
                reloadingStrategy.setRefreshDelay(0);
                fileConfig.setReloadingStrategy(reloadingStrategy);
                fileConfigs.add(fileConfig);
            }
        } catch (ConfigurationException ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config init failed {}", ex);
            }
        }
    }
    return !fileConfigs.isEmpty();
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) FileChangedReloadingStrategy(org.apache.commons.configuration.reloading.FileChangedReloadingStrategy) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 8 with FileConfiguration

use of org.apache.commons.configuration.FileConfiguration in project zaproxy by zaproxy.

the class OptionsParamApiUnitTest method shouldUseDefaultValuesWhenLoadingFileConfigurationWithInvalidValues.

@Test
public void shouldUseDefaultValuesWhenLoadingFileConfigurationWithInvalidValues() {
    // Given
    OptionsParamApi param = new OptionsParamApi();
    FileConfiguration config = createTestConfigWithInvalidValues();
    // When
    param.load(config);
    // Then
    assertThat(param.isEnabled(), is(equalTo(true)));
    assertThat(param.isSecureOnly(), is(equalTo(false)));
    assertThat(param.isDisableKey(), is(equalTo(false)));
    assertThat(param.isIncErrorDetails(), is(equalTo(false)));
    assertThat(param.isAutofillKey(), is(equalTo(false)));
    assertThat(param.isEnableJSONP(), is(equalTo(false)));
    assertThat(param.getRealKey(), is(equalTo("")));
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) Test(org.junit.Test)

Example 9 with FileConfiguration

use of org.apache.commons.configuration.FileConfiguration in project zaproxy by zaproxy.

the class ExtensionParamUnitTest method shouldParseLoadedFileConfiguration.

@Test
public void shouldParseLoadedFileConfiguration() {
    // Given
    ExtensionParam param = new ExtensionParam();
    FileConfiguration config = createTestConfig(false, true, false, true, true);
    // When
    param.load(config);
    // Then
    assertThat(param.isExtensionEnabled("Extension 1"), is(equalTo(false)));
    assertThat(param.isExtensionEnabled("Extension 2"), is(equalTo(true)));
    assertThat(param.isExtensionEnabled("Extension 3"), is(equalTo(false)));
    assertThat(param.isExtensionEnabled("Extension 4"), is(equalTo(true)));
    assertThat(param.isExtensionEnabled("Extension 5"), is(equalTo(true)));
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) Test(org.junit.Test)

Example 10 with FileConfiguration

use of org.apache.commons.configuration.FileConfiguration in project zaproxy by zaproxy.

the class ExtensionParamUnitTest method shouldNotPersistNullExtensionNamesOrNullEnabledState.

@Test
public void shouldNotPersistNullExtensionNamesOrNullEnabledState() {
    // Given
    ExtensionParam param = new ExtensionParam();
    FileConfiguration config = createTestConfig();
    param.load(config);
    Map<String, Boolean> states = new HashMap<>();
    states.put(null, Boolean.FALSE);
    states.put("Extension 2", null);
    // When
    param.setExtensionsState(states);
    // Then
    assertThat(param.getConfig().getKeys().hasNext(), is(equalTo(false)));
}
Also used : FileConfiguration(org.apache.commons.configuration.FileConfiguration) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

FileConfiguration (org.apache.commons.configuration.FileConfiguration)13 Test (org.junit.Test)10 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 FileChangedReloadingStrategy (org.apache.commons.configuration.reloading.FileChangedReloadingStrategy)1 RegexAutoTagScanner (org.zaproxy.zap.extension.pscan.scanner.RegexAutoTagScanner)1