Search in sources :

Example 1 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zeppelin by apache.

the class ZeppelinConfiguration method create.

/**
   * Load from resource.
   *url = ZeppelinConfiguration.class.getResource(ZEPPELIN_SITE_XML);
   * @throws ConfigurationException
   */
public static synchronized ZeppelinConfiguration create() {
    if (conf != null) {
        return conf;
    }
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    URL url;
    url = ZeppelinConfiguration.class.getResource(ZEPPELIN_SITE_XML);
    if (url == null) {
        ClassLoader cl = ZeppelinConfiguration.class.getClassLoader();
        if (cl != null) {
            url = cl.getResource(ZEPPELIN_SITE_XML);
        }
    }
    if (url == null) {
        url = classLoader.getResource(ZEPPELIN_SITE_XML);
    }
    if (url == null) {
        LOG.warn("Failed to load configuration, proceeding with a default");
        conf = new ZeppelinConfiguration();
    } else {
        try {
            LOG.info("Load configuration from " + url);
            conf = new ZeppelinConfiguration(url);
        } catch (ConfigurationException e) {
            LOG.warn("Failed to load configuration from " + url + " proceeding with a default", e);
            conf = new ZeppelinConfiguration();
        }
    }
    LOG.info("Server Host: " + conf.getServerAddress());
    if (conf.useSsl() == false) {
        LOG.info("Server Port: " + conf.getServerPort());
    } else {
        LOG.info("Server SSL Port: " + conf.getServerSslPort());
    }
    LOG.info("Context Path: " + conf.getServerContextPath());
    LOG.info("Zeppelin Version: " + Util.getVersion());
    return conf;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) URL(java.net.URL)

Example 2 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project OpenAttestation by OpenAttestation.

the class TAConfig method gatherConfiguration.

private Configuration gatherConfiguration(String propertiesFilename, Properties defaults) {
    CompositeConfiguration composite = new CompositeConfiguration();
    // first priority are properties defined on the current JVM (-D switch or through web container)
    SystemConfiguration system = new SystemConfiguration();
    dumpConfiguration(system, "system");
    composite.addConfiguration(system);
    // second priority are properties defined on the classpath (like user's home directory)        
    try {
        // user's home directory (assuming it's on the classpath!)
        readPropertiesFile("/" + propertiesFilename, composite);
    } catch (IOException ex) {
        log.info("Did not find " + propertiesFilename + " on classpath", ex);
    }
    // third priority are properties defined in standard install location
    System.out.println("TAConfig os.name=" + System.getProperty("os.name"));
    ArrayList<File> files = new ArrayList<File>();
    // windows-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("win")) {
        System.out.println("TAConfig user.home=" + System.getProperty("user.home"));
        files.add(new File("C:" + File.separator + "Intel" + File.separator + "CloudSecurity" + File.separator + propertiesFilename));
        files.add(new File(System.getProperty("user.home") + File.separator + propertiesFilename));
    }
    // linux-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("linux") || System.getProperty("os.name", "").toLowerCase().equals("unix")) {
        files.add(new File("./config/" + propertiesFilename));
        files.add(new File("/etc/oat-client/" + propertiesFilename));
    }
    // this line specific to TA for backwards compatibility, not needed in AS/AH
    files.add(new File(System.getProperty("app.path") + File.separator + propertiesFilename));
    // add all the files we found
    for (File f : files) {
        try {
            if (f.exists() && f.canRead()) {
                PropertiesConfiguration standard = new PropertiesConfiguration(f);
                dumpConfiguration(standard, "file:" + f.getAbsolutePath());
                composite.addConfiguration(standard);
            }
        } catch (ConfigurationException ex) {
            log.error(null, ex);
        }
    }
    // last priority are the defaults that were passed in, we use them if no better source was found
    if (defaults != null) {
        MapConfiguration defaultconfig = new MapConfiguration(defaults);
        dumpConfiguration(defaultconfig, "default");
        composite.addConfiguration(defaultconfig);
    }
    dumpConfiguration(composite, "composite");
    return composite;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 3 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project pinot by linkedin.

the class SingleNodeServerStarter method buildServerConfig.

/**
   * Construct from config file path
   * @param configFilePath Path to the config file
   * @throws Exception
   */
public static void buildServerConfig(File configFilePath) throws Exception {
    if (!configFilePath.exists()) {
        LOGGER.error("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
        throw new ConfigurationException("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
    }
    // build _serverConf
    final PropertiesConfiguration serverConf = new PropertiesConfiguration();
    serverConf.setDelimiterParsingDisabled(false);
    serverConf.load(configFilePath);
    _serverConf = new ServerConf(serverConf);
}
Also used : ServerConf(com.linkedin.pinot.server.conf.ServerConf) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 4 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project archaius by Netflix.

the class OverridingPropertiesConfiguration method getConfigFromPropertiesFile.

public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded, String... nextLoadKeys) throws FileNotFoundException {
    if (loaded.contains(startingUrl.toExternalForm())) {
        logger.warn(startingUrl + " is already loaded");
        return null;
    }
    PropertiesConfiguration propConfig = null;
    try {
        propConfig = new OverridingPropertiesConfiguration(startingUrl);
        logger.info("Loaded properties file " + startingUrl);
    } catch (ConfigurationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof FileNotFoundException) {
            throw (FileNotFoundException) cause;
        } else {
            throw new RuntimeException(e);
        }
    }
    if (nextLoadKeys == null) {
        return propConfig;
    }
    String urlString = startingUrl.toExternalForm();
    String base = urlString.substring(0, urlString.lastIndexOf("/"));
    loaded.add(startingUrl.toString());
    loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys);
    return propConfig;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 5 with ConfigurationException

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

the class AddOnLoader method saveAddOnsRunState.

private static void saveAddOnsRunState(Map<AddOn, List<String>> runnableAddOns) {
    HierarchicalConfiguration config = (HierarchicalConfiguration) Model.getSingleton().getOptionsParam().getConfig();
    config.clearTree(ADDONS_RUNNABLE_BASE_KEY);
    int i = 0;
    for (Map.Entry<AddOn, List<String>> runnableAddOnEntry : runnableAddOns.entrySet()) {
        String elementBaseKey = ADDONS_RUNNABLE_KEY + "(" + i + ").";
        AddOn addOn = runnableAddOnEntry.getKey();
        config.setProperty(elementBaseKey + ADDON_RUNNABLE_ID_KEY, addOn.getId());
        config.setProperty(elementBaseKey + ADDON_RUNNABLE_VERSION_KEY, Integer.valueOf(addOn.getFileVersion()));
        String extensionBaseKey = elementBaseKey + ADDON_RUNNABLE_ALL_EXTENSIONS_KEY;
        for (String extension : runnableAddOnEntry.getValue()) {
            config.addProperty(extensionBaseKey, extension);
        }
        i++;
    }
    try {
        Model.getSingleton().getOptionsParam().getConfig().save();
    } catch (ConfigurationException e) {
        logger.error("Failed to save state of runnable add-ons:", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) ArrayList(java.util.ArrayList) List(java.util.List) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)166 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)63 IOException (java.io.IOException)53 File (java.io.File)40 URL (java.net.URL)17 Configuration (org.apache.commons.configuration.Configuration)15 MalformedURLException (java.net.MalformedURLException)13 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)13 BeforeClass (org.junit.BeforeClass)10 ArrayList (java.util.ArrayList)9 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)9 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)7 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 Iterator (java.util.Iterator)4 JCommander (com.beust.jcommander.JCommander)3