Java Code Examples for org.apache.commons.configuration.PropertiesConfiguration#load()

The following examples show how to use org.apache.commons.configuration.PropertiesConfiguration#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegatedAccessDaoImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Loads our SQL statements from the appropriate properties file
 
 * @param vendor	DB vendor string. Must be one of mysql, oracle, hsqldb
 */
private void initStatements(String vendor) {
	
	URL url = getClass().getClassLoader().getResource(vendor + ".properties"); 
	
	try {
		statements = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		statements.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		statements.setThrowExceptionOnMissing(true);	//throw exception if no prop
		statements.setDelimiterParsingDisabled(true); //don't split properties
		statements.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage(), e);
		return;
	}
}
 
Example 2
Source File: BaseSecurityTest.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static String writeConfiguration(final PropertiesConfiguration configuration) throws Exception {
    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = BaseSecurityTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    PropertiesConfiguration configuredProperties = new PropertiesConfiguration();
    configuredProperties.load(url);

    configuredProperties.copy(configuration);

    String persistDir = TestUtils.getTempDirectory();
    configuredProperties.setProperty("atlas.authentication.method.file", "true");
    configuredProperties.setProperty("atlas.authentication.method.file.filename", persistDir
            + "/users-credentials");
    configuredProperties.setProperty("atlas.auth.policy.file",persistDir
            + "/policy-store.txt" );
    TestUtils.writeConfiguration(configuredProperties, persistDir + File.separator +
            ApplicationProperties.APPLICATION_PROPERTIES);
    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);
    ApplicationProperties.forceReload();
    return persistDir;
}
 
Example 3
Source File: PullFileLoader.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Load a {@link Properties} compatible path using fallback as fallback.
 * @return The {@link Config} in path with fallback as fallback.
 * @throws IOException
 */
private Config loadJavaPropsWithFallback(Path propertiesPath, Config fallback) throws IOException {

  PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
  try (InputStreamReader inputStreamReader = new InputStreamReader(this.fs.open(propertiesPath),
      Charsets.UTF_8)) {
    propertiesConfiguration.setDelimiterParsingDisabled(ConfigUtils.getBoolean(fallback,
  		  PROPERTY_DELIMITER_PARSING_ENABLED_KEY, DEFAULT_PROPERTY_DELIMITER_PARSING_ENABLED_KEY));
    propertiesConfiguration.load(inputStreamReader);

    Config configFromProps =
        ConfigUtils.propertiesToConfig(ConfigurationConverter.getProperties(propertiesConfiguration));

    return ConfigFactory.parseMap(ImmutableMap.of(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY,
        PathUtils.getPathWithoutSchemeAndAuthority(propertiesPath).toString()))
        .withFallback(configFromProps)
        .withFallback(fallback);
  } catch (ConfigurationException ce) {
    throw new IOException(ce);
  }
}
 
Example 4
Source File: PropertiesConfigurationWrapper.java    From StatsAgg with Apache License 2.0 6 votes vote down vote up
private void readPropertiesConfigurationFile(File propertiesFile) {
    
    if (propertiesFile == null) {
        return;
    }
    
    try {
        if (propertiesFile.exists()) {
            configurationDirectory_ = propertiesFile.getParent();
            configurationFilename_ = propertiesFile.getName();

            propertiesConfiguration_ = new PropertiesConfiguration();
            propertiesConfiguration_.setDelimiterParsingDisabled(true);
            propertiesConfiguration_.setAutoSave(false);
            propertiesConfiguration_.load(propertiesFile);
        }
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        
        configurationDirectory_ = null;
        configurationFilename_ = null;
        propertiesConfiguration_ = null;
    }
}
 
Example 5
Source File: DefaultConsumer.java    From IGUANA with GNU Affero General Public License v3.0 6 votes vote down vote up
public void consume(byte[] data) {
	if (data == null) {
		System.out.println(data);
	} else {
		String dataStr = RabbitMQUtils.getObject(data);
		PropertiesConfiguration config = new PropertiesConfiguration();
		try(StringReader sreader = new StringReader(dataStr)) {
			config.load(sreader);
			System.out.println("Config received");
		} catch (ConfigurationException e1) {
			LOGGER.error("Could not read configuration. Must ignore it... Sorry :(", e1);

		}
		if (!config.isEmpty()) {
			cmanager.receiveData(config);
		} else {

			LOGGER.error("Empty configuration. Must ignore it... Sorry :(");

		}
	}
}
 
Example 6
Source File: DelegatedAccessDaoImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Loads our SQL statements from the appropriate properties file
 
 * @param vendor	DB vendor string. Must be one of mysql, oracle, hsqldb
 */
private void initStatements(String vendor) {
	
	URL url = getClass().getClassLoader().getResource(vendor + ".properties"); 
	
	try {
		statements = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		statements.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		statements.setThrowExceptionOnMissing(true);	//throw exception if no prop
		statements.setDelimiterParsingDisabled(true); //don't split properties
		statements.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage(), e);
		return;
	}
}
 
Example 7
Source File: GoPubMedSeparateConceptRetrievalExecutor.java    From bioasq with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
  super.initialize(context);
  String conf = UimaContextHelper.getConfigParameterStringValue(context, "conf");
  PropertiesConfiguration gopubmedProperties = new PropertiesConfiguration();
  try {
    gopubmedProperties.load(getClass().getResourceAsStream(conf));
  } catch (ConfigurationException e) {
    throw new ResourceInitializationException(e);
  }
  service = new GoPubMedService(gopubmedProperties);
  pages = UimaContextHelper.getConfigParameterIntValue(context, "pages", 1);
  hits = UimaContextHelper.getConfigParameterIntValue(context, "hits", 1);
  bopQueryStringConstructor = new BagOfPhraseQueryStringConstructor();
  timeout = UimaContextHelper.getConfigParameterIntValue(context, "timeout", 4);
  limit = UimaContextHelper.getConfigParameterIntValue(context, "limit", Integer.MAX_VALUE);
}
 
Example 8
Source File: PinLaterMySQLBackendTest.java    From pinlater with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  QUEUE_NAME = "pinlater_mysql_backend_test";
  // If there is no local MySQL, skip this test.
  boolean isLocalMySQLRunning = LocalMySQLChecker.isRunning();
  Assume.assumeTrue(isLocalMySQLRunning);
  PropertiesConfiguration configuration = new PropertiesConfiguration();
  try {
    configuration.load(ClassLoader.getSystemResourceAsStream("pinlater.test.properties"));
  } catch (ConfigurationException e) {
    throw new RuntimeException(e);
  }
  System.setProperty("backend_config", "mysql.local.json");

  backend = new PinLaterMySQLBackend(
      configuration, "localhost", System.currentTimeMillis());
}
 
Example 9
Source File: PropertyPatternMessageColorizer.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
public void init(InputStream in) throws ConfigurationException {
  propertiesConfiguration = new PropertiesConfiguration();
  propertiesConfiguration.setDelimiterParsingDisabled(true);
  propertiesConfiguration.load(in, "UTF-8");
  configuration = new DataConfiguration(propertiesConfiguration);
  configuration.setDelimiterParsingDisabled(true);
  String pa = configuration.getString(PROP_PATTERN);
  int flags = 0;
  flags = flags | (configuration.getBoolean(PROP_PATTERN_CANON_EQ, false) ? Pattern.CANON_EQ : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_CASE_INSENSITIVE, false) ? Pattern.CASE_INSENSITIVE : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_COMMENTS, false) ? Pattern.COMMENTS : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_DOTALL, false) ? Pattern.DOTALL : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_LITERAL, false) ? Pattern.LITERAL : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_MULTILINE, false) ? Pattern.MULTILINE : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_UNICODE_CASE, false) ? Pattern.UNICODE_CASE : 0);
  flags = flags | (configuration.getBoolean(PROP_PATTERN_UNIX_LINES, false) ? Pattern.UNIX_LINES : 0);

  pattern = Pattern.compile(pa, flags);
  groupCount = countGroups(pattern);
  name = configuration.getString(PROP_NAME, "NAME NOT SET!");
  description = configuration.getString(PROP_DESCRIPTION, "DESCRIPTION NOT SET!");
  testMessage = configuration.getString(PROP_TEST_MESSAGE, "");

}
 
Example 10
Source File: RegisterUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static void registerBackends() {
    String confFile = "/backend.properties";
    InputStream input = RegisterUtil.class.getClass()
                                    .getResourceAsStream(confFile);
    E.checkState(input != null,
                 "Can't read file '%s' as stream", confFile);

    PropertiesConfiguration props = new PropertiesConfiguration();
    props.setDelimiterParsingDisabled(true);
    try {
        props.load(input);
    } catch (ConfigurationException e) {
        throw new HugeException("Can't load config file: %s", e, confFile);
    }

    HugeConfig config = new HugeConfig(props);
    List<String> backends = config.get(DistOptions.BACKENDS);
    for (String backend : backends) {
        registerBackend(backend);
    }
}
 
Example 11
Source File: SSSDTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void loadSSSDConfiguration() throws ConfigurationException {
    log.info("Reading SSSD configuration from classpath from: " + sssdConfigPath);
    InputStream is = SSSDTest.class.getClassLoader().getResourceAsStream(sssdConfigPath);
    sssdConfig = new PropertiesConfiguration();
    sssdConfig.load(is);
    sssdConfig.setListDelimiter(',');
}
 
Example 12
Source File: ConfigurationHelper.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Loads configuration from a specified path.
 *
 * @param path the path to try first as a resource, then as a file
 * @throws ConfigurationLoadException if the configuration could not be
 *         loaded.
 * @returns properties loaded from the specified path or null.
 */
public Configuration fromFile(File path) throws ConfigurationLoadException {
  PropertiesConfiguration configuration = setupConfiguration(new PropertiesConfiguration());
  configuration.setFile(path);
  try {
    configuration.load();
    return configuration;
  } catch (ConfigurationException e) {
    throw new ConfigurationLoadException(
        "Encountered a problem reading the provided configuration file \"" + path + "\"!", e);
  }
}
 
Example 13
Source File: MessageResources.java    From unitime with Apache License 2.0 5 votes vote down vote up
private Configuration getConfiguration(String name) {
	Configuration configuration = null;
	URL url = Thread.currentThread().getContextClassLoader().getResource(name);
	if (url != null) {
		PropertiesConfiguration pc = new PropertiesConfiguration();
		pc.setURL(url);
		
		// Set reloading strategy 
		String dynamicReload = ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload", null);
		if (dynamicReload!=null && dynamicReload.equalsIgnoreCase("true")) {
			long refreshDelay = Constants.getPositiveInteger(
					ApplicationProperties.getProperty("tmtbl.properties.dynamic_reload_interval"), 15000 );
			
			FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
			strategy.setRefreshDelay(refreshDelay); 
			pc.setReloadingStrategy(strategy);
			
			pc.addConfigurationListener(new MessageResourcesCfgListener(pc.getBasePath()));
		}			
		
		try {
			pc.load();
			configuration = pc;
		} catch (ConfigurationException e) {
			Debug.error("Message Resources configuration exception: " + e.getMessage());
		}
	}

	return configuration;
}
 
Example 14
Source File: ConfigurationHelper.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Loads configuration from a specified path.
 *
 * @param path the path to try first as a resource, then as a file
 * @throws ConfigurationLoadException if the configuration could not be
 *         loaded.
 * @returns properties loaded from the specified path or null.
 */
public Configuration fromFile(URL path) throws ConfigurationLoadException {
  PropertiesConfiguration configuration = setupConfiguration(new PropertiesConfiguration());
  configuration.setURL(path);
  try {
    configuration.load();
    return configuration;
  } catch (ConfigurationException e) {
    throw new ConfigurationLoadException(
        "Encountered a problem reading the provided configuration file \"" + path + "\"!", e);
  }
}
 
Example 15
Source File: PropertiesConfigurationWrapper.java    From StatsAgg with Apache License 2.0 5 votes vote down vote up
private void readPropertiesConfigurationFile(String filePathAndFilename) {
    
    if (filePathAndFilename == null) {
        return;
    }
    
    try {
        File propertiesFile = new File(filePathAndFilename);
        boolean doesFileExist = FileIo.doesFileExist(filePathAndFilename);
        
        if (doesFileExist) {
            configurationDirectory_ = propertiesFile.getParent();
            configurationFilename_ = propertiesFile.getName();

            propertiesConfiguration_ = new PropertiesConfiguration();
            propertiesConfiguration_.setDelimiterParsingDisabled(true);
            propertiesConfiguration_.setAutoSave(false);
            propertiesConfiguration_.load(propertiesFile);
        }
    }
    catch (Exception e) {
        logger.error(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        
        configurationDirectory_ = null;
        configurationFilename_ = null;
        propertiesConfiguration_ = null;
    }
}
 
Example 16
Source File: JobConfigurationUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Load the properties from the specified file into a {@link Properties} object.
 *
 * @param fileName the name of the file to load properties from
 * @param conf configuration object to determine the file system to be used
 * @return a new {@link Properties} instance
 */
public static Properties fileToProperties(String fileName, Configuration conf)
    throws IOException, ConfigurationException {

  PropertiesConfiguration propsConfig = new PropertiesConfiguration();
  Path filePath = new Path(fileName);
  URI fileURI = filePath.toUri();

  if (fileURI.getScheme() == null && fileURI.getAuthority() == null) {
    propsConfig.load(FileSystem.getLocal(conf).open(filePath));
  } else {
    propsConfig.load(filePath.getFileSystem(conf).open(filePath));
  }
  return ConfigurationConverter.getProperties(propsConfig);
}
 
Example 17
Source File: ConfigurationUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static PropertiesConfiguration loadFromFile(File file, boolean listParsing) throws ConfigurationException {
    PropertiesConfiguration configuration = newPropertiesConfiguration(listParsing);
    String path = file.isAbsolute() ? file.getParent() : null;
    String filename = file.isAbsolute() ? file.getName() : file.getPath();
    configuration.setBasePath(path);
    configuration.load(filename);
    return configuration;
}
 
Example 18
Source File: TutorialEntityProviderImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void initConfig() {
	
	URL url = getClass().getClassLoader().getResource("Tutorial.config"); 
	
	try {
		tutorialProps = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
		tutorialProps.setReloadingStrategy(new InvariantReloadingStrategy());	//don't watch for reloads
		tutorialProps.setThrowExceptionOnMissing(false);	//throw exception if no prop
		tutorialProps.setDelimiterParsingDisabled(true); //don't split properties
		tutorialProps.load(url); //now load our file
	} catch (ConfigurationException e) {
		log.error(e.getClass() + ": " + e.getMessage());
		return;
	}
}
 
Example 19
Source File: NegativeSSLAndKerberosTest.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
    providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri();

    String persistDir = TestUtils.getTempDirectory();

    setupKDCAndPrincipals();
    setupCredentials();

    // client will actually only leverage subset of these properties
    final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl);

    persistSSLClientConfiguration(configuration);

    TestUtils.writeConfiguration(configuration, persistDir + File.separator +
        ApplicationProperties.APPLICATION_PROPERTIES);

    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = NegativeSSLAndKerberosTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    configuration.load(url);

    configuration.setProperty(TLS_ENABLED, true);
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.keytab",userKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.principal","dgi/localhost@"+kdc.getRealm());

    configuration.setProperty("atlas.authentication.method.file", "false");
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.method.kerberos.principal", "HTTP/localhost@" + kdc.getRealm());
    configuration.setProperty("atlas.authentication.method.kerberos.keytab", httpKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.method.kerberos.name.rules",
            "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT");

    configuration.setProperty("atlas.authentication.method.file", "true");
    configuration.setProperty("atlas.authentication.method.file.filename", persistDir
            + "/users-credentials");
    configuration.setProperty("atlas.auth.policy.file",persistDir
            + "/policy-store.txt" );

    TestUtils.writeConfiguration(configuration, persistDir + File.separator +
            ApplicationProperties.APPLICATION_PROPERTIES);

    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);

    // save original setting
    originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);

    dgiClient = new AtlasClient(configuration, DGI_URL);


    secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) {
        @Override
        public Configuration getConfiguration() {
            return configuration;
        }
    };
    secureEmbeddedServer.getServer().start();
}
 
Example 20
Source File: SSLAndKerberosTest.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
    providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri();

    String persistDir = TestUtils.getTempDirectory();

    setupKDCAndPrincipals();
    setupCredentials();

    // client will actually only leverage subset of these properties
    final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl);

    persistSSLClientConfiguration(configuration);

    TestUtils.writeConfiguration(configuration, persistDir + File.separator +
        ApplicationProperties.APPLICATION_PROPERTIES);

    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = SSLAndKerberosTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    configuration.load(url);
    configuration.setProperty(TLS_ENABLED, true);
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.keytab",userKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.principal","dgi/localhost@"+kdc.getRealm());

    configuration.setProperty("atlas.authentication.method.file", "false");
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.method.kerberos.principal", "HTTP/localhost@" + kdc.getRealm());
    configuration.setProperty("atlas.authentication.method.kerberos.keytab", httpKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.method.kerberos.name.rules",
            "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT");

    configuration.setProperty("atlas.authentication.method.file", "true");
    configuration.setProperty("atlas.authentication.method.file.filename", persistDir
            + "/users-credentials");
    configuration.setProperty("atlas.auth.policy.file",persistDir
            + "/policy-store.txt" );

    TestUtils.writeConfiguration(configuration, persistDir + File.separator +
      "atlas-application.properties");

    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);

    subject = loginTestUser();
    UserGroupInformation.loginUserFromSubject(subject);
    UserGroupInformation proxyUser = UserGroupInformation.createProxyUser(
        "testUser",
        UserGroupInformation.getLoginUser());

    // save original setting
    originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);

    originalHomeDir = System.getProperty("atlas.home");
    System.setProperty("atlas.home", TestUtils.getTargetDirectory());

    dgiCLient = proxyUser.doAs(new PrivilegedExceptionAction<AtlasClient>() {
        @Override
        public AtlasClient run() throws Exception {
            return new AtlasClient(configuration, DGI_URL);
        }
    });


    secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) {
        @Override
        public PropertiesConfiguration getConfiguration() {
            return configuration;
        }
    };
    secureEmbeddedServer.getServer().start();
}