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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Usage

From source file:com.appeligo.config.ConfigurationService.java

public static void main(String[] args) {
    ConfigurationService.setRootDir(new File("src/main/test/config"));
    ConfigurationService.init();//from w w w  .  j av  a 2s  .c om

    AbstractConfiguration config = getConfiguration("system");
    System.out.println("testPath=" + config.getString("testPath"));
    System.out.println("testValue=" + config.getString("testValue"));
}

From source file:com.netflix.zuul.dependency.ribbon.RibbonConfig.java

private static void setIfNotDefined(String key, String value) {
    final AbstractConfiguration config = ConfigurationManager.getConfigInstance();
    if (config.getString(key) == null) {
        LOG.info("Setting default NIWS Property " + key + "=" + value);
        config.setProperty(key, value);/*www . j  ava2s  .com*/
    }
}

From source file:com.nesscomputing.config.ConfigDynamicMBean.java

private static Map<String, Object> toMap(Config config) {
    AbstractConfiguration configuration = config.getConfiguration();
    Iterator<String> keys = configuration.getKeys();

    Map<String, Object> result = Maps.newHashMap();
    while (keys.hasNext()) {
        String key = keys.next();
        result.put(key, configuration.getString(key));
    }/*  www .  ja  va 2 s.c  o m*/

    return result;
}

From source file:gov.nih.nci.security.authentication.AuthenticationManagerFactory.java

/**
 * This methods instantiate an implementation of the {@link AuthenticationManager} and returns it to the calling method.
 * It reads the config file using the Application Context/Name provided as parameter. If an entry is found,
 * it retrieves the name of the class and instantiate an object of the same and returns it to the calling method.
 * However if the entry is not found, then the default {@link CommonAuthenticationManager} Class is instantiated and
 * returned to the calling method/*from   w  w  w. j av  a2 s . co  m*/
 *
 * The path for the application config file should be configured in the system properties file as shown below
 * <p>
 * <blockquote>
 *
 * <pre>
 * e.g. gov.nih.nci.security.configFile=/foo/bar/ApplicationSecurityConfig.xml
 * </pre>
 *
 * </blockquote>
 * <p>
 * Where <code>gov.nih.nci.security.configFile</code> is the property name and <code>/foo/bar/ApplicationSecurityConfig.xml</code> is the fully
 * qualified file path. This configuration file contains which implementation of Authentication Manager is to be used
 *
 * @param applicationContextName The name or context of the calling application. This parameter is used to retrieve
 * the implementation class for that Application from the property file if it is configured.
 * NOTE: that the application name/context should be same as those configured in the configuration/property files
 * @return An instance of the class implementating the AuthenticationManager interface. This could the client custom
 * implementation or the default provided Authentication Manager
 * @throws CSException If there are any errors in obtaining the correct instance of the {@link AuthenticationManager}
 * @throws CSConfigurationException If there are any configuration errors during obtaining the {@link AuthenticationManager}
 */
public static AuthenticationManager getAuthenticationManager(String applicationContextName)
        throws CSException, CSConfigurationException {

    AuthenticationManager authenticationManager = null;
    String applicationManagerClassName = null;
    try {
        AbstractConfiguration config = ConfigurationHelper.getInstance(applicationContextName)
                .getConfiguration();
        LockoutManager.initialize(config.getString("PASSWORD_LOCKOUT_TIME"),
                config.getString("ALLOWED_LOGIN_TIME"), config.getString("ALLOWED_ATTEMPTS"));
        applicationManagerClassName = ApplicationSecurityConfigurationParser
                .getAuthenticationManagerClass(applicationContextName);
    } catch (CSException cse) {
        if (log.isDebugEnabled())
            log.debug("Authentication|" + applicationContextName
                    + "||getAuthenticationManager|Error|Error in reading the Application Security Config file and trying to initialize the manager in new way|");
        authenticationManager = (AuthenticationManager) new CommonAuthenticationManager();
        authenticationManager.initialize(applicationContextName);
        LockoutManager.initialize(Constants.LOCKOUT_TIME, Constants.ALLOWED_LOGIN_TIME,
                Constants.ALLOWED_ATTEMPTS);
        if (log.isDebugEnabled())
            log.debug("Authentication|" + applicationContextName
                    + "||getAuthenticationManager|Success|Initializing Common Authentication Manager in new way|");
    }
    if (null == applicationManagerClassName || applicationManagerClassName.equals("")) {
        if (log.isDebugEnabled())
            log.debug("Authentication|" + applicationContextName
                    + "||getAuthenticationManager|Success|Initializing Common Authentication Manager|");
        authenticationManager = (AuthenticationManager) new CommonAuthenticationManager();
        authenticationManager.initialize(applicationContextName);

    } else {
        try {
            authenticationManager = (AuthenticationManager) (Class.forName(applicationManagerClassName))
                    .newInstance();
            authenticationManager.initialize(applicationContextName);

            if (log.isDebugEnabled())
                log.debug("Authentication|" + applicationContextName
                        + "||getAuthenticationManager|Success|Initializing Custom Authentication Manager "
                        + applicationManagerClassName + "|");
        } catch (Exception exception) {
            if (log.isDebugEnabled())
                log.debug("Authentication|" + applicationContextName
                        + "||getAuthenticationManager|Failure| Error initializing Custom Authentication Manager "
                        + applicationManagerClassName + "|" + exception.getMessage());
            throw new CSConfigurationException(
                    "Error in loading the configured AuthenticationManager for the Application", exception);
        }

    }
    return authenticationManager;
}

From source file:com.opentable.config.TestNewstyleConfig.java

@Test
public void testNewstyle() throws Exception {
    final URL path = TestNewstyleConfig.class.getResource("/newstyle-config");
    final Config config = Config.getConfig(path.toString(), "common,common/test,app,app/test");
    final AbstractConfiguration props = config.getConfiguration();

    assertEquals("a", props.getString("prop1"));
    assertEquals("b", props.getString("prop2"));
    assertEquals("c", props.getString("prop3"));
    assertEquals("d", props.getString("prop4"));
}

From source file:me.ineson.demo.app.ConfigTest.java

@Test
public void testGetString() {
    AbstractConfiguration mockAbstractConfiguration = mock(XMLConfiguration.class);
    when(mockAbstractConfiguration.getString("testApp.key1")).thenReturn("testCall");
    Config config = new Config("testApp", mockAbstractConfiguration);

    String value = config.getString("key1");

    verify(mockAbstractConfiguration, times(1)).getString("testApp.key1");
    verifyNoMoreInteractions(mockAbstractConfiguration);

    Assert.assertEquals("testCall", value);
}

From source file:me.ineson.demo.app.ConfigTest.java

@Test
public void testGetStringManadtorySuccess() {
    AbstractConfiguration mockAbstractConfiguration = mock(XMLConfiguration.class);
    when(mockAbstractConfiguration.getString("testApp.key2")).thenReturn("testCall2");
    Config config = new Config("testApp", mockAbstractConfiguration);

    String value = config.getStringManadtory("key2");

    verify(mockAbstractConfiguration, times(1)).getString("testApp.key2");
    verifyNoMoreInteractions(mockAbstractConfiguration);

    Assert.assertEquals("testCall2", value);
}

From source file:me.ineson.demo.app.ConfigTest.java

/**
 * /*from w  ww  .java 2 s  .  c  om*/
 */
@Test
public void testGetStringManadtoryFail() {
    AbstractConfiguration mockAbstractConfiguration = mock(XMLConfiguration.class);
    when(mockAbstractConfiguration.getString("testAppF.key3")).thenReturn(null);
    Config config = new Config("testAppF", mockAbstractConfiguration);

    try {
        config.getStringManadtory("key3");
        Assert.fail("Mandatory ");
    } catch (IllegalStateException e) {
        // Should fail
    }

    verify(mockAbstractConfiguration, times(1)).getString("testAppF.key3");
    verifyNoMoreInteractions(mockAbstractConfiguration);
}

From source file:com.dialectify.ws.artifacts.EdgeListener.java

void initZuul() throws Exception, IllegalAccessException, InstantiationException {

    RequestContext.setContextClass(NFRequestContext.class);

    CounterFactory.initialize(new Counter());
    TracerFactory.initialize(new Tracer());

    final AbstractConfiguration config = ConfigurationManager.getConfigInstance();

    final String preFiltersPath = config.getString(ZUUL_FILTER_PRE_PATH);
    final String postFiltersPath = config.getString(ZUUL_FILTER_POST_PATH);
    final String routingFiltersPath = config.getString(ZUUL_FILTER_ROUTING_PATH);
    final String customPath = config.getString(ZUUL_FILTER_CUSTOM_PATH);

    FilterLoader.getInstance().setCompiler(new GroovyCompiler());
    FilterFileManager.setFilenameFilter(new GroovyFileFilter());
    if (customPath == null) {
        FilterFileManager.init(5, preFiltersPath, postFiltersPath, routingFiltersPath);
    } else {/*from   w  w  w  . j a  va 2  s  . c om*/
        FilterFileManager.init(5, preFiltersPath, postFiltersPath, routingFiltersPath, customPath);
    }
}

From source file:com.netflix.adminresources.resources.WebAdminComponent.java

@PostConstruct
public void init() {
    AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance();
    if (configInstance.containsKey(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME)) {
        logger.info("Admin container default page already set to: " + configInstance
                .getString(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME + ", not overriding."));
        return;//  w  ww  . ja v a  2  s .c  om
    }
    configInstance.setProperty(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME, ADMINRES_WEBADMIN_INDEX_HTML);
    logger.info("Set the default page for admin container to: " + ADMINRES_WEBADMIN_INDEX_HTML);
}