Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

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

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.netflix.iep.archaius1.ArchaiusModuleTest.java

@Test
public void getValueRuntime() {
    Key<SettableConfig> key = Key.get(SettableConfig.class, RuntimeLayer.class);
    Injector injector = Guice.createInjector(testModule);
    SettableConfig runtime = injector.getInstance(key);
    Configuration root = injector.getInstance(IEP_CONFIG);

    Assert.assertEquals("b", root.getString("a"));
    Assert.assertEquals("dynamic", root.getString("c"));

    runtime.setProperty("a", "runtime");
    runtime.setProperty("c", "runtime");
    Assert.assertEquals("runtime", root.getString("a"));
    Assert.assertEquals("runtime", root.getString("c"));

    runtime.clearProperty("a");
    Assert.assertEquals("b", root.getString("a"));
    Assert.assertEquals("runtime", root.getString("c"));
}

From source file:com.evolveum.midpoint.init.RepositoryFactory.java

private String getFactoryClassName(Configuration config) {
    String className = config.getString(REPOSITORY_FACTORY_CLASS);
    if (StringUtils.isEmpty(className)) {
        LOGGER.error("RepositoryServiceFactory implementation class name ({}) not found in configuration. "
                + "Provided configuration:\n{}", new Object[] { REPOSITORY_FACTORY_CLASS, config });
        throw new SystemException(
                "RepositoryServiceFactory implementation class name (" + REPOSITORY_FACTORY_CLASS
                        + ") not found in configuration. Provided configuration:\n" + config);
    }//  www .j  ava  2  s  .c o  m

    return className;
}

From source file:es.udc.gii.common.eaf.plugin.parameter.LogAnnealing.java

@Override
public void configure(Configuration conf) {
    try {//from   w  w w. j a v a  2 s. com
        if (conf.containsKey("Counter.Class")) {
            this.counter = (StopTestPlugin) Class.forName(conf.getString("Counter.Class")).newInstance();
            this.counter.configure(conf.subset("Counter"));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.boozallen.cognition.ingest.storm.spout.StormKafkaSpout.java

SpoutConfig getSpoutConfig(Configuration conf) {
    String zookeeper = conf.getString(ZOOKEEPER);
    String brokerPath = conf.getString(BROKER_PATH);
    String topic = conf.getString(TOPIC);
    String zkRoot = conf.getString(ZK_ROOT);
    String spoutId = conf.getString(SPOUT_ID);
    boolean forceFromStart = conf.getBoolean(FORCE_FROM_START, DEFAULT_FORCE_FROM_START);

    logger.debug("Zookeeper: {}", zookeeper);
    logger.debug("BrokerPath: {}", brokerPath);
    logger.debug("Topic: {}", topic);
    logger.debug("ZkRoot: {}", zkRoot);
    logger.debug("Force From Start: {}", forceFromStart);

    ZkHosts zkHosts;//from  www  .  ja  v a 2s.co  m
    if (StringUtils.isBlank(brokerPath)) {
        zkHosts = new ZkHosts(zookeeper);
    } else {
        zkHosts = new ZkHosts(zookeeper, brokerPath);
    }
    SpoutConfig spoutConfig = new SpoutConfig(zkHosts, topic, zkRoot, spoutId);
    spoutConfig.forceFromStart = forceFromStart;
    return spoutConfig;
}

From source file:com.netflix.iep.archaius1.ArchaiusModuleTest.java

@Test
@Ignore/*from  w  ww  .  j a va  2  s  .co  m*/
public void getValues() {
    Configuration cfg = Guice.createInjector(testModule).getInstance(IEP_CONFIG);
    Assert.assertEquals("b", cfg.getString("a"));
    Assert.assertEquals("dynamic", cfg.getString("c"));
}

From source file:com.microrisc.simply.network.SimpleNetworkConnectionStorageFactory.java

/** Creates and returns UDP configuration settings. */
private UDPConnectionInfo getUDPConnectionInfo(Configuration networkConfig) throws UnknownHostException {
    String hostStr = networkConfig.getString("host");
    InetAddress ipAddress = InetAddress.getByName(hostStr);
    int port = networkConfig.getInt("port");
    return new BaseUDPConnectionInfo(ipAddress, port);
}

From source file:edu.kit.dama.rest.util.auth.impl.SwaggerApiKeyAuthenticator.java

@Override
public boolean performCustomConfiguration(Configuration pConfig) throws ConfigurationException {
    apiKey = pConfig.getString("apiKey");
    if (apiKey == null) {
        throw new ConfigurationException("Property 'apiKey' is missing.");
    }/*from w w  w  .  ja v a 2  s .  co  m*/
    apiUser = pConfig.getString("apiUser");
    if (apiUser == null) {
        throw new ConfigurationException("Property 'apiUser' is missing.");
    }
    try {
        Role role = (Role) GroupServiceLocal.getSingleton().getMaximumRole(
                new GroupId(Constants.WORLD_GROUP_ID), new UserId(apiUser),
                AuthorizationContext.factorySystemContext());
        if (role.lessThan(Role.MANAGER)) {
            throw new ConfigurationException(
                    "The provided api user '" + apiUser + "' has an insufficient role in group "
                            + Constants.WORLD_GROUP_ID + ". (" + role + " < MANAGER)");
        }
    } catch (EntityNotFoundException | UnauthorizedAccessAttemptException e) {
        throw new ConfigurationException(
                "Failed to check configured api user '" + apiUser + "'. Probably the user does not exist.");
    }
    return true;
}

From source file:com.parallax.server.blocklyprop.services.impl.AuthenticationServiceImpl.java

@Inject
public void setConfiguration(Configuration configuration) {
    this.configuration = configuration;
    userService = new CloudSessionUserService(configuration.getString("cloudsession.baseurl"));
}

From source file:com.dcsquare.hivemq.plugin.stormpathplugin.StormpathPluginModule.java

@Provides
@Singleton/*w w w. j  a  va2s . c o m*/
private Application registerApplication(final Configuration configuration) {
    try {
        final String apiKeyId = configuration.getString("stormpath.apiKey.id");
        final String apiKeySecret = configuration.getString("stormpath.apiKey.secret");

        final DefaultApiKey apiKey = new DefaultApiKey(apiKeyId, apiKeySecret);
        final Client client = new ClientBuilder().setApiKey(apiKey).build();
        final String applicationName = configuration.getString("stormpath.application.name");

        final Tenant tenant = client.getCurrentTenant();
        Application application = null;

        final ApplicationList applications = tenant
                .getApplications(Applications.where(Applications.name().eqIgnoreCase(applicationName)));

        // Iterator is necessary, to check if the ApplicationsList is empty, because there's no size() method or something equal, in the ApplicationsList class.
        final Iterator<Application> iterator = applications.iterator();

        if (iterator.hasNext()) {
            application = iterator.next();
        }

        if (application == null) {
            application = client.instantiate(Application.class);
            application.setName(applicationName);
            application = client.getCurrentTenant()
                    .createApplication(Applications.newCreateRequestFor(application).createDirectory().build());
        }

        return application;
    } catch (Exception e) {
        log.error("An error occured while authenticating with Stormpath", e);
    }
    return null;
}

From source file:com.evolveum.midpoint.init.ConfigurationLoadTest.java

@Test(enabled = false)
public void t01simpleConfigTest() {
    LOGGER.info("---------------- simpleConfigTest -----------------");

    System.clearProperty("midpoint.home");
    LOGGER.info("midpoint.home => " + System.getProperty("midpoint.home"));

    assertNull(System.getProperty("midpoint.home"), "midpoint.home");

    StartupConfiguration sc = new StartupConfiguration();
    assertNotNull(sc);// w  w  w.ja v  a 2 s .  com
    sc.init();
    Configuration c = sc.getConfiguration("midpoint.repository");
    assertEquals(c.getString("repositoryServiceFactoryClass"),
            "com.evolveum.midpoint.repo.xml.XmlRepositoryServiceFactory");
    LOGGER.info(sc.toString());

    @SuppressWarnings("unchecked")
    Iterator<String> i = c.getKeys();

    while (i.hasNext()) {
        String key = i.next();
        LOGGER.info("  " + key + " = " + c.getString(key));
    }

    assertEquals(c.getInt("port"), 1984);
    assertEquals(c.getString("serverPath"), "");

}