Example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration.

Prototype

public PropertiesConfiguration(URL url) throws ConfigurationException 

Source Link

Document

Creates and loads the extended properties from the specified URL.

Usage

From source file:io.fabric8.apiman.ApimanStarter.java

/**
 * Main entry point for the API Manager micro service.
 * @param args the arguments/* w  w  w .  j  ava 2 s  .  co m*/
 * @throws Exception when any unhandled exception occurs
 */
public static final void main(String[] args) throws Exception {

    Fabric8ManagerApiMicroService microService = new Fabric8ManagerApiMicroService();

    boolean isTestMode = getSystemPropertyOrEnvVar(APIMAN_TESTMODE, false);
    if (isTestMode)
        log.info("Apiman running in TestMode");

    boolean isSsl = getSystemPropertyOrEnvVar(APIMAN_SSL, false);
    log.info("Apiman running in SSL: " + isSsl);
    String protocol = "http";
    if (isSsl)
        protocol = "https";

    File apimanConfigFile = new File(APIMAN_PROPERTIES);
    String esUsername = null;
    String esPassword = null;
    if (apimanConfigFile.exists()) {
        PropertiesConfiguration config = new PropertiesConfiguration(apimanConfigFile);
        esUsername = config.getString("es.username");
        esPassword = config.getString("es.password");
        if (Utils.isNotNullOrEmpty(esPassword))
            esPassword = new String(Base64.getDecoder().decode(esPassword), StandardCharsets.UTF_8).trim();
        setConfigProp(APIMAN_ELASTICSEARCH_USERNAME, esUsername);
        setConfigProp(APIMAN_ELASTICSEARCH_PASSWORD, esPassword);
    }
    URL elasticEndpoint = null;
    // Require ElasticSearch and the Gateway Services to to be up before proceeding
    if (isTestMode) {
        URL url = new URL("https://localhost:9200");
        elasticEndpoint = waitForDependency(url, "", "elasticsearch-v1", "status", "200", esUsername,
                esPassword);
    } else {
        String defaultEsUrl = protocol + "://elasticsearch-v1:9200";
        String esURL = getSystemPropertyOrEnvVar(APIMAN_ELASTICSEARCH_URL, defaultEsUrl);
        URL url = new URL(esURL);
        elasticEndpoint = waitForDependency(url, "", "elasticsearch-v1", "status", "200", esUsername,
                esPassword);
        log.info("Found " + elasticEndpoint);
        String defaultGatewayUrl = protocol + "://apiman-gateway:7777";
        gatewayUrl = getSystemPropertyOrEnvVar(APIMAN_GATEWAY_URL, defaultGatewayUrl);

        URL gatewayEndpoint = waitForDependency(new URL(gatewayUrl), "/api/system/status", "apiman-gateway",
                "up", "true", null, null);
        log.info("Found " + gatewayEndpoint);
    }

    setConfigProp("apiman.plugins.repositories", "http://repo1.maven.org/maven2/");
    setConfigProp("apiman-manager.plugins.registries",
            "http://cdn.rawgit.com/apiman/apiman-plugin-registry/1.2.6.Final/registry.json");
    setFabric8Props(elasticEndpoint);
    if (isSsl) {
        microService.startSsl();
        microService.joinSsl();
    } else {
        microService.start();
        microService.join();
    }
}

From source file:gobblin.scheduler.Worker.java

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Usage: Worker <work configuration properties file>");
        System.exit(1);/*  w w w .j  av a2 s  .c o  m*/
    }

    // Load framework configuration properties
    Configuration config = new PropertiesConfiguration(args[0]);
    // Start the worker
    new Worker(ConfigurationConverter.getProperties(config)).start();
}

From source file:com.xlson.standalonewar.Starter.java

/**
 * @param args the command line arguments
 */// w  w w. j av  a 2 s  . c  o m
public static void main(String[] args) {
    try {
        defaultProperties = new PropertiesConfiguration(
                Starter.class.getClassLoader().getResource("webserver.properties").toURI().toURL());

        appendClasspath(defaultProperties.getList("webserver.extraClasspath"));

        config = loadConfig();

        final String PROP_NAME_WEBSERVER_TIMEOUT = defaultProperties.getString("PROP_NAME_WEBSERVER_TIMEOUT",
                "webserver.timeout");
        int timeout = Integer.parseInt(getString(PROP_NAME_WEBSERVER_TIMEOUT, "0"));
        start();
        if (timeout != 0) {
            Thread.sleep(timeout);
            stop();
        }
    } catch (Exception ex) {
        logger.error("error", ex);
        System.err.println(ex.getMessage());
        System.exit(-1);
    }
}

From source file:gobblin.test.TestWorker.java

@SuppressWarnings("all")
public static void main(String[] args) throws Exception {
    // Build command-line options
    Option configOption = OptionBuilder.withArgName("framework config file")
            .withDescription("Configuration properties file for the framework").hasArgs().withLongOpt("config")
            .create('c');
    Option jobConfigsOption = OptionBuilder.withArgName("job config files")
            .withDescription("Comma-separated list of job configuration files").hasArgs()
            .withLongOpt("jobconfigs").create('j');
    Option modeOption = OptionBuilder.withArgName("run mode")
            .withDescription("Test mode (schedule|run); 'schedule' means scheduling the jobs, "
                    + "whereas 'run' means running the jobs immediately")
            .hasArg().withLongOpt("mode").create('m');
    Option helpOption = OptionBuilder.withArgName("help").withDescription("Display usage information")
            .withLongOpt("help").create('h');

    Options options = new Options();
    options.addOption(configOption);/*from  www  .j a v  a  2s .com*/
    options.addOption(jobConfigsOption);
    options.addOption(modeOption);
    options.addOption(helpOption);

    // Parse command-line options
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption('h')) {
        printUsage(options);
        System.exit(0);
    }

    // Start the test worker with the given configuration properties
    Configuration config = new PropertiesConfiguration(cmd.getOptionValue('c'));
    Properties properties = ConfigurationConverter.getProperties(config);
    TestWorker testWorker = new TestWorker(properties);
    testWorker.start();

    // Job running mode
    Mode mode = Mode.valueOf(cmd.getOptionValue('m').toUpperCase());

    // Get the list of job configuration files
    List<String> jobConfigFiles = Lists
            .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(cmd.getOptionValue('j')));

    CountDownLatch latch = new CountDownLatch(jobConfigFiles.size());
    for (String jobConfigFile : jobConfigFiles) {
        // For each job, load the job configuration, then run or schedule the job.
        Properties jobProps = new Properties();
        jobProps.load(new FileReader(jobConfigFile));
        jobProps.putAll(properties);
        testWorker.runJob(jobProps, mode, new TestJobListener(latch));
    }
    // Wait for all jobs to finish
    latch.await();

    testWorker.stop();
}

From source file:net.sf.mpaxs.spi.computeHost.StartUp.java

/**
 *
 * @param args//from  www.jav  a2s  .  co m
 */
public static void main(String args[]) {
    FileHandler handler;
    try {
        handler = new FileHandler("computeHost.log");
        Logger logger = Logger.getLogger(StartUp.class.getName());
        logger.addHandler(handler);
    } catch (IOException ex) {
        Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
    }

    Options options = new Options();
    Option[] optionArray = new Option[] { OptionBuilder.withArgName("configuration").hasArg().isRequired()
            .withDescription("URL to configuration file for compute host").create("c") };
    for (Option opt : optionArray) {
        options.addOption(opt);
    }
    if (args.length == 0) {
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp(StartUp.class.getCanonicalName(), options, true);
        System.exit(1);
    }
    GnuParser gp = new GnuParser();
    try {
        CommandLine cl = gp.parse(options, args);
        try {
            URL configURL = new URL(cl.getOptionValue("c"));
            PropertiesConfiguration cfg = new PropertiesConfiguration(configURL);
            StartUp su = new StartUp(cfg);
        } catch (ConfigurationException ex) {
            Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MalformedURLException ex) {
            Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (ParseException ex) {
        Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:edu.pitt.dbmi.facebase.hd.HumanDataController.java

/** Entry point to application.  Firstly it gathers properties from hd.properties file on CLASSPATH 
 * Most properties are localisms to do with file path information, database connection strings, 
 * and TrueCrypt program operation.  Hopefully the application can run by only editing entries in 
 * hd.properties file.  hd.properties has normal java properties fragility but also app-specific 
 * fragility--for example, the sshServerUrl must end with a colon, as in root@server:
 * Notice that program properties can also be set below--by filling in the empty strings following 
 * declaration AND commenting-out the try-catch clause that follows which gathers these properties 
 * from hd.properties.  /*  ww w .  j  a v a2 s. c o m*/
 */
public static void main(String[] args) {
    /** holds human-readable error data to be passed to addError() */
    String errorString = "";

    log.info("HumanDataController Started");
    /** length of time to sleep in between each polling loop, 5secs is responsive, 5mins is alot */
    String sleepFor = "";
    /** Prefix path where TrueCrypt write operations will be performed (i.e. /tmp or /var/tmp), no trailing-slash */
    String trueCryptBasePath = "";
    /** TrueCrypt volume file extension (probably .tc or .zip) */
    String trueCryptExtension = "";
    /** Middle-of-path directory name to be created where TrueCrypt volume will be mounted */
    String trueCryptMountpoint = "";
    /** Human Data Server database credentials */
    String hdDbUser = "";
    String hdPasswd = "";
    String hdJdbcUrl = "";
    /** Hub database credentials */
    String fbDbUser = "";
    String fbPasswd = "";
    String fbJdbcUrl = "";
    /** Full path to truecrypt binary, (ie /usr/bin/truecrypt) */
    String trueCryptBin = "";
    /** Full path to scp binary, (ie /usr/bin/scp) */
    String scpBin = "";
    /** user@host portion of scp destination argument (ie. root@www.server.com:) */
    String sshServerUrl = "";
    /** file full path portion of scp destination argument (ie. /usr/local/downloads/) */
    String finalLocation = "";
    /** Full path to touch binary, (ie /bin/touch) */
    String touchBin = "";
    /** hardcoded truecrypt parameters; run "truecrypt -h" to learn about these */
    String algorithm = "";
    String hash = "";
    String filesystem = "";
    String volumeType = "";
    String randomSource = "";
    String protectHidden = "";
    String extraArgs = "";

    /** truecrypt parameters are packed into a map so we only pass one arg (this map) to method invoking truecrypt */
    HashMap<String, String> trueCryptParams = new HashMap<String, String>();
    trueCryptParams.put("trueCryptBin", "");
    trueCryptParams.put("scpBin", "");
    trueCryptParams.put("sshServerUrl", "");
    trueCryptParams.put("finalLocation", "");
    trueCryptParams.put("touchBin", "");
    trueCryptParams.put("algorithm", "");
    trueCryptParams.put("hash", "");
    trueCryptParams.put("filesystem", "");
    trueCryptParams.put("volumeType", "");
    trueCryptParams.put("randomSource", "");
    trueCryptParams.put("protectHidden", "");
    trueCryptParams.put("extraArgs", "");

    try {
        /** The properties file name is hardcoded to hd.properties--cannot be changed--this file must be on or at root of classpath */
        final Configuration config = new PropertiesConfiguration("hd.properties");
        sleepFor = config.getString("sleepFor");
        hubURL = config.getString("hubURL");
        responseTrigger = config.getString("responseTrigger");
        trueCryptBasePath = config.getString("trueCryptBasePath");
        trueCryptExtension = config.getString("trueCryptExtension");
        trueCryptMountpoint = config.getString("trueCryptMountpoint");
        hdDbUser = config.getString("hdDbUser");
        hdPasswd = config.getString("hdPasswd");
        hdJdbcUrl = config.getString("hdJdbcUrl");
        fbDbUser = config.getString("fbDbUser");
        fbPasswd = config.getString("fbPasswd");
        fbJdbcUrl = config.getString("fbJdbcUrl");
        trueCryptBin = config.getString("trueCryptBin");
        scpBin = config.getString("scpBin");
        sshServerUrl = config.getString("sshServerUrl");
        finalLocation = config.getString("finalLocation");
        touchBin = config.getString("touchBin");
        algorithm = config.getString("algorithm");
        hash = config.getString("hash");
        filesystem = config.getString("filesystem");
        volumeType = config.getString("volumeType");
        randomSource = config.getString("randomSource");
        protectHidden = config.getString("protectHidden");
        extraArgs = config.getString("extraArgs");

        trueCryptParams.put("trueCryptBin", trueCryptBin);
        trueCryptParams.put("scpBin", scpBin);
        trueCryptParams.put("sshServerUrl", sshServerUrl);
        trueCryptParams.put("finalLocation", finalLocation);
        trueCryptParams.put("touchBin", touchBin);
        trueCryptParams.put("algorithm", algorithm);
        trueCryptParams.put("hash", hash);
        trueCryptParams.put("filesystem", filesystem);
        trueCryptParams.put("volumeType", volumeType);
        trueCryptParams.put("randomSource", randomSource);
        trueCryptParams.put("protectHidden", protectHidden);
        trueCryptParams.put("extraArgs", extraArgs);
        log.debug("properties file loaded successfully");
    } catch (final ConfigurationException e) {
        errorString = "Properties file problem";
        String logString = e.getMessage();
        addError(errorString, logString);
        log.error(errorString);
    }
    log.debug("initialize static class variable HumanDataManager declared earlier");
    hdm = new HumanDataManager(hdDbUser, hdPasswd, hdJdbcUrl);
    log.debug("declare and initialize InstructionQueueManager");
    InstructionQueueManager iqm = new InstructionQueueManager(fbDbUser, fbPasswd, fbJdbcUrl);
    log.debug("pass to the logfile/console all startup parameters for troubleshooting");
    log.info("HumanDataController started with these settings from hd.properties: " + "hubURL=" + hubURL + " "
            + "responseTrigger=" + responseTrigger + " " + "trueCryptBasePath=" + trueCryptBasePath + " "
            + "trueCryptExtension=" + trueCryptExtension + " " + "trueCryptMountpoint=" + trueCryptMountpoint
            + " " + "hdDbUser=" + hdDbUser + " " + "hdPasswd=" + hdPasswd + " " + "hdJdbcUrl=" + hdJdbcUrl + " "
            + "fbDbUser=" + fbDbUser + " " + "fbPasswd=" + fbPasswd + " " + "fbJdbcUrl=" + fbJdbcUrl + " "
            + "trueCryptBin=" + trueCryptBin + " " + "scpBin=" + scpBin + " " + "sshServerUrl=" + sshServerUrl
            + " " + "finalLocation=" + finalLocation + " " + "touchBin=" + touchBin + " " + "algorithm="
            + algorithm + " " + "hash=" + hash + " " + "filesystem=" + filesystem + " " + "volumeType="
            + volumeType + " " + "randomSource=" + randomSource + " " + "protectHidden=" + protectHidden + " "
            + "extraArgs=" + extraArgs);
    log.debug("Enter infinite loop where program will continuously poll Hub server database for new requests");
    while (true) {
        log.debug("LOOP START");
        try {
            Thread.sleep(Integer.parseInt(sleepFor) * 1000);
        } catch (InterruptedException ie) {
            errorString = "Failed to sleep, got interrupted.";
            log.error(errorString, ie);
            addError(errorString, ie.getMessage());
        }
        log.debug(
                "About to invoke InstructionQueueManager.queryInstructions()--Hibernate to fb_queue starts NOW");
        List<InstructionQueueItem> aiqi = iqm.queryInstructions();
        log.debug("Currently there are " + aiqi.size() + " items in the queue");
        InstructionQueueItem iqi;
        String instructionName = "";
        log.debug("About to send http request -status- telling Hub we are alive:");
        httpGetter("status", "0");
        if (aiqi.size() > 0) {
            log.debug(
                    "There is at least one request, status=pending, queue item; commence processing of most recent item");
            iqi = aiqi.get(0);
            log.debug("About to get existing user key, or create a new one, via fb_keychain Hibernate");
            FbKey key = hdm.queryKey(iqi.getUid());
            log.debug(
                    "About to pull the JSON Instructions string, and other items, from the InstructionQueueItem");
            String instructionsString = iqi.getInstructions();
            instructionName = iqi.getName();
            log.debug("About to create a new FileManager object with:");
            log.debug(instructionName + trueCryptBasePath + trueCryptExtension + trueCryptMountpoint);
            FileManager fm = new FileManager(instructionName, trueCryptBasePath, trueCryptExtension,
                    trueCryptMountpoint);
            ArrayList<Instructions> ali = new ArrayList<Instructions>();
            log.debug(
                    "FileManager.makeInstructionsObjects() creates multiple Instruction objects from the InstructionQueueItem.getInstructions() value");
            if (fm.makeInstructionsObjects(instructionsString, ali)) {
                log.debug("FileManager.makeInstructionsObjects() returned true");
            } else {
                errorString = "FileManager.makeInstructionsObjects() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            log.debug(
                    "FileManager.makeFiles() uses its list of Instruction objects and calls its makeFiles() method to make/get requested data files");
            if (fm.makeFiles(ali)) {
                log.debug("FileManager.makeFiles() returned true");
            } else {
                errorString = "FileManager.makeFiles() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            //sends the size/100000 as seconds(100k/sec)...needs to be real seconds.");
            long bytesPerSecond = 100000;
            Long timeToMake = new Long(fm.getSize() / bytesPerSecond);
            String timeToMakeString = timeToMake.toString();
            log.debug("Send http request -status- to Hub with total creation time estimate:");
            log.debug(timeToMakeString);
            httpGetter("status", timeToMakeString);
            log.debug(
                    "Update the queue_item row with the total size of the data being packaged with InstructionQueueManager.updateInstructionSize()");
            if (iqm.updateInstructionSize(fm.getSize(), iqi.getQid())) {
                log.debug("InstructionQueueManager.updateInstructionSize() returned true");
            } else {
                errorString = "InstructionQueueManager.updateInstructionSize() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            log.debug("About to make new TrueCryptManager with these args:");
            log.debug(key.getEncryption_key() + fm.getSize() + fm.getTrueCryptPath()
                    + fm.getTrueCryptVolumePath() + trueCryptParams);
            TrueCryptManager tcm = new TrueCryptManager(key.getEncryption_key(), fm.getSize(),
                    fm.getTrueCryptPath(), fm.getTrueCryptVolumePath(), trueCryptParams);
            if (tcm.touchVolume()) {
                log.debug("TrueCryptManager.touchVolume() returned true, touched file");
            } else {
                errorString = "TrueCryptManager.touchVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.makeVolume()) {
                log.debug("TrueCryptManager.makeVolume() returned true, created TrueCrypt volume");
            } else {
                errorString = "TrueCryptManager.makeVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.mountVolume()) {
                log.debug("TrueCryptManager.mountVolume() returned true, mounted TrueCrypt volume");
            } else {
                errorString = "TrueCryptManager.mountVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (fm.copyFilesToVolume(ali)) {
                log.debug(
                        "TrueCryptManager.copyFilesToVolume() returned true, copied requested files to mounted volume");
            } else {
                errorString = "TrueCryptManager.copyFilesToVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.disMountVolume()) {
                log.debug("TrueCryptManager.disMountVolume() returned true, umounted TrueCrypt volume");
            } else {
                errorString = "TrueCryptManager.disMountVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.sendVolumeToFinalLocation()) {
                log.debug(
                        "TrueCryptManager.sendVolumeToFinalLocation() returned true, copied TrueCrypt volume to retreivable, final location");
            } else {
                errorString = "TrueCryptManager.sendVolumeToFinalLocation() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (iqm.updateInstructionToCompleted(tcm.getFinalLocation() + fm.getTrueCryptFilename(),
                    fm.getSize(), iqi.getQid(), getErrors(), getLogs())) {
                log.debug("InstructionQueueManager.updateInstructionToCompleted() returned true");
                log.debug(
                        "Processing of queue item is almost finished, updated fb_queue item row with location, size, status, errors, logs:");
                log.debug(tcm.getFinalLocation() + fm.getTrueCryptFilename() + fm.getSize() + iqi.getQid()
                        + getErrors() + getLogs());
            } else {
                errorString = "InstructionQueueManager.updateInstructionToCompleted() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            log.debug("About to send http request -update- telling Hub which item is finished.");
            httpGetter("update", iqi.getHash());
            log.debug("Finished processing pending queue item, status should now be complete or error");
        } else {
            log.debug("Zero queue items");
        }
        log.debug("LOOP END");
    }
}

From source file:com.croer.javaorange.util.Configuration.java

public static CompositeConfiguration getCONFIGURATION() {
    if (CONFIGURATION == null) {
        List lc = new ArrayList();
        try {/*from w w w. ja va 2 s .  c om*/
            PropertiesConfiguration pc1 = new PropertiesConfiguration("prueba.properties");
            //                PropertiesConfiguration pc2 = new PropertiesConfiguration("mvc.properties");
            lc.add(pc1);
            //                lc.add(pc2);
        } catch (ConfigurationException ex) {
            Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
        }
        CONFIGURATION = new CompositeConfiguration(lc);
    }
    return CONFIGURATION;
}

From source file:it.cavalleasy.app.camel.configuration.ConfigurationManager.java

public static void addConfiguration(URL file) {
    try {//from  w ww.j a va 2 s .  c  om
        config.addConfiguration(new PropertiesConfiguration(file));
    } catch (ConfigurationException ex) {
        logger.error("Error raised adding custom configuration file ");
    }
}

From source file:com.lyncode.oai.proxy.core.ConfigurationManager.java

public static void initialize(String filepath) throws ConfigurationException {
    config = new PropertiesConfiguration(filepath);
}

From source file:club.jmint.crossing.client.config.Config.java

public static PropertiesConfiguration loadPropertiesConfigFile(String file) {

    PropertiesConfiguration config = null;
    try {//  w ww .j a  va  2s  . c  om
        config = new PropertiesConfiguration(file);
    } catch (ConfigurationException e) {
        CrossLog.printStackTrace(e);
    }

    return config;
}