List of usage examples for org.apache.commons.configuration AbstractConfiguration getString
public String getString(String key)
From source file:com.netflix.explorers.AppConfigGlobalModelContext.java
@Inject public AppConfigGlobalModelContext(@Named("explorerAppName") String appName) { final String propertiesFileName = appName + "-explorers-app.properties"; try {/* w w w . j a v a 2 s . c om*/ ConfigurationManager.loadPropertiesFromResources(propertiesFileName); } catch (IOException e) { LOG.error(String.format( "Exception loading properties file - %s, Explorers application may not work correctly ", propertiesFileName)); } AbstractConfiguration configuration = ConfigurationManager.getConfigInstance(); environmentName = configuration.getString(PROPERTY_ENVIRONMENT_NAME); currentRegion = configuration.getString(PROPERTY_CURRENT_REGION); applicationVersion = (String) configuration.getProperty(PROPERTY_APPLICATION_VERSION); applicationName = (String) configuration.getProperty(PROPERTY_APPLICATION_NAME); isLocal = configuration.getBoolean(PROPERTY_IS_LOCAL, false); homePageUrl = configuration.getString(PROPERTY_HOME_PAGE); defaultPort = configuration.getShort(PROPERTY_DEFAULT_PORT, (short) 8080); dataCenter = configuration.getString(PROPERTY_DATA_CENTER); defaultExplorerName = configuration.getString(PROPERTY_DEFAULT_EXPLORER); try { Iterator<String> dcKeySet = configuration.getKeys(PROPERTIES_PREFIX + ".dc"); while (dcKeySet.hasNext()) { String dcKey = dcKeySet.next(); String key = StringUtils.substringBefore(dcKey, "."); String attr = StringUtils.substringAfter(dcKey, "."); CrossLink link = links.get(key); if (link == null) { link = new CrossLink(); links.put(key, link); } BeanUtils.setProperty(link, attr, configuration.getProperty(dcKey)); } } catch (Exception e) { LOG.error("Exception in constructing links map ", e); throw new RuntimeException(e); } }
From source file:com.kixeye.chassis.bootstrap.BootstrapConfiguration.java
@Bean @SuppressWarnings("resource") public AbstractConfiguration applicationConfiguration() throws ClassNotFoundException { AppMetadata appMetadata = appMetadata(); ServerInstanceContext serverInstanceContext = serverInstanceContext(); if (appEnvironment == null && serverInstanceContext != null) { appEnvironment = serverInstanceContext.getEnvironment(); }/*from w w w. jav a 2 s. co m*/ ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(appMetadata.getName(), appEnvironment, addSystemConfigs, reflections()); configurationBuilder.withConfigurationProvider(configurationProvider()); configurationBuilder.withServerInstanceContext(serverInstanceContext()); configurationBuilder.withApplicationProperties(appMetadata.getPropertiesResourceLocation()); configurationBuilder.withScanModuleConfigurations(scanModuleConfigurations); configurationBuilder .withAppVersion(appMetadata.getDeclaringClass().getPackage().getImplementationVersion()); AbstractConfiguration configuration = configurationBuilder.build(); if (serverInstanceContext != null) { serverInstanceContext.setAppName(appMetadata.getName()); serverInstanceContext .setVersion(configuration.getString(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName())); } return configuration; }
From source file:com.netflix.zuul.StartServer.java
void initZuul() throws Exception, IllegalAccessException, InstantiationException { RequestContext.setContextClass(NFRequestContext.class); CounterFactory.initialize(new Counter()); TracerFactory.initialize(new Tracer()); LOG.info("Starting Groovy Filter file manager"); 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 {// w ww .ja v a 2 s . c om FilterFileManager.init(5, preFiltersPath, postFiltersPath, routingFiltersPath, customPath); } LOG.info("Groovy Filter file manager started"); }
From source file:com.kixeye.chassis.support.logging.LoggingConfiguration.java
@PostConstruct public void initialize() { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); if (config.containsKey(LOGBACK_CONFIG_NAME)) { System.out.println("Loading logging config."); reloadLogging(config.getString(LOGBACK_CONFIG_NAME)); }/*from w w w . j a v a 2 s . c om*/ config.addConfigurationListener(new ConfigurationListener() { @Override public synchronized void configurationChanged(ConfigurationEvent event) { if ((event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY || event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY) && StringUtils.equalsIgnoreCase(LOGBACK_CONFIG_NAME, event.getPropertyName()) && event.getPropertyValue() != null && !event.isBeforeUpdate()) { System.out.println("Reloading logging config."); reloadLogging((String) event.getPropertyValue()); } } }); ConfigurationListener flumeConfigListener = new ConfigurationListener() { private FlumeLoggerLoader loggerLoader = null; public synchronized void configurationChanged(ConfigurationEvent event) { if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY || event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY || event.getType() == AbstractConfiguration.EVENT_CLEAR_PROPERTY)) { return; } if (FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY.equals(event.getPropertyName())) { if ("true".equals(event.getPropertyValue())) { if (loggerLoader == null) { // construct the bean loggerLoader = (FlumeLoggerLoader) applicationContext .getBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, "chassis"); } // else we already have one so we're cool } else { if (loggerLoader != null) { // delete the bean ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) applicationContext .getParentBeanFactory(); beanFactory.destroyBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, loggerLoader); loggerLoader = null; } // else we don't have any so we're cool } } else if (FlumeLoggerLoader.RELOAD_PROPERTIES.contains(event.getPropertyValue())) { // only reload if we're already running - otherwise ignore if (loggerLoader != null) { // delete the bean ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) applicationContext .getParentBeanFactory(); beanFactory.destroyBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, loggerLoader); loggerLoader = null; // construct the bean loggerLoader = (FlumeLoggerLoader) applicationContext .getBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, "chassis"); } // else we don't have any so we're cool } } }; config.addConfigurationListener(flumeConfigListener); flumeConfigListener.configurationChanged(new ConfigurationEvent(this, AbstractConfiguration.EVENT_SET_PROPERTY, FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY, config.getProperty(FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY), false)); }
From source file:com.kixeye.chassis.transport.websocket.WebSocketTransportConfiguration.java
@Bean(initMethod = "start", destroyMethod = "stop") @Order(0)//from ww w . jav a 2 s. c o m public Server webSocketServer(@Value("${websocket.enabled:false}") boolean websocketEnabled, @Value("${websocket.hostname:}") String websocketHostname, @Value("${websocket.port:-1}") int websocketPort, @Value("${secureWebsocket.enabled:false}") boolean secureWebsocketEnabled, @Value("${secureWebsocket.hostname:}") String secureWebsocketHostname, @Value("${secureWebsocket.port:-1}") int secureWebsocketPort, @Value("${secureWebsocket.selfSigned:false}") boolean selfSigned, @Value("${secureWebsocket.mutualSsl:false}") boolean mutualSsl, @Value("${secureWebsocket.keyStorePath:}") String keyStorePath, @Value("${secureWebsocket.keyStoreData:}") String keyStoreData, @Value("${secureWebsocket.keyStorePassword:}") String keyStorePassword, @Value("${secureWebsocket.keyManagerPassword:}") String keyManagerPassword, @Value("${secureWebsocket.trustStorePath:}") String trustStorePath, @Value("${secureWebsocket.trustStoreData:}") String trustStoreData, @Value("${secureWebsocket.trustStorePassword:}") String trustStorePassword, @Value("${securewebsocket.excludedCipherSuites:}") String[] excludedCipherSuites) throws Exception { // set up servlets ServletContextHandler context = new ServletContextHandler( ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setErrorHandler(null); context.setWelcomeFiles(new String[] { "/" }); for (final MessageSerDe serDe : serDes) { // create the websocket creator final WebSocketCreator webSocketCreator = new WebSocketCreator() { public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) { // this will have spring construct a new one for every session ActionInvokingWebSocket webSocket = forwardingWebSocket(); webSocket.setSerDe(serDe); webSocket.setUpgradeRequest(req); webSocket.setUpgradeResponse(resp); return webSocket; } }; // configure the websocket servlet ServletHolder webSocketServlet = new ServletHolder(new WebSocketServlet() { private static final long serialVersionUID = -3022799271546369505L; @Override public void configure(WebSocketServletFactory factory) { factory.setCreator(webSocketCreator); } }); Map<String, String> webSocketProperties = new HashMap<>(); AbstractConfiguration config = ConfigurationManager.getConfigInstance(); Iterator<String> webSocketPropertyKeys = config.getKeys("websocket"); while (webSocketPropertyKeys.hasNext()) { String key = webSocketPropertyKeys.next(); webSocketProperties.put(key.replaceFirst(Pattern.quote("websocket."), ""), config.getString(key)); } webSocketServlet.setInitParameters(webSocketProperties); context.addServlet(webSocketServlet, "/" + serDe.getMessageFormatName() + "/*"); } // create the server Server server; if (metricRegistry == null || !monitorThreadpool) { server = new Server(); server.setHandler(context); } else { server = new Server(new InstrumentedQueuedThreadPool(metricRegistry)); InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry); instrumented.setHandler(context); server.setHandler(instrumented); } // set up connectors if (websocketEnabled) { InetSocketAddress address = StringUtils.isBlank(websocketHostname) ? new InetSocketAddress(websocketPort) : new InetSocketAddress(websocketHostname, websocketPort); JettyConnectorRegistry.registerHttpConnector(server, address); } if (secureWebsocketEnabled) { InetSocketAddress address = StringUtils.isBlank(secureWebsocketHostname) ? new InetSocketAddress(secureWebsocketPort) : new InetSocketAddress(secureWebsocketHostname, secureWebsocketPort); JettyConnectorRegistry.registerHttpsConnector(server, address, selfSigned, mutualSsl, keyStorePath, keyStoreData, keyStorePassword, keyManagerPassword, trustStorePath, trustStoreData, trustStorePassword, excludedCipherSuites); } return server; }
From source file:com.nesscomputing.service.discovery.server.announce.ConfigStaticAnnouncer.java
private Map<UUID, Map<String, String>> getAnnouncements() { final AbstractConfiguration subconfig = config.getConfiguration(CONFIG_ROOT); final Iterator<String> keys = subconfig.getKeys(); final Map<UUID, Map<String, String>> configTree = Maps.newHashMap(); while (keys.hasNext()) { final String key = keys.next(); final String id = StringUtils.substringBefore(key, "."); UUID serviceId;/*from w ww. ja va 2 s.c om*/ try { serviceId = UUID.fromString(id); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException(String.format("Invalid serviceId \"%s\"", id), e); } Map<String, String> configMap = configTree.get(serviceId); if (configMap == null) { configTree.put(serviceId, configMap = Maps.newHashMap()); } configMap.put(StringUtils.substringAfter(key, "."), subconfig.getString(key)); } return configTree; }
From source file:netflix.adminresources.resources.WebAdminComponent.java
@PostConstruct public void init() { final AbstractConfiguration configInst = ConfigurationManager.getConfigInstance(); if (configInst.containsKey(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME)) { logger.info("Admin container default page already set to: " + configInst.getString(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME + ", not overriding.")); return;/*www. j av a 2s . c o m*/ } configInst.setProperty(AdminResourcesContainer.DEFAULT_PAGE_PROP_NAME, ADMINRES_WEBADMIN_INDEX_HTML); logger.info("Set the default page for admin container to: " + ADMINRES_WEBADMIN_INDEX_HTML); }
From source file:org.apache.servicecomb.config.TestConfigUtil.java
@Test public void testAddConfig() { Map<String, Object> config = new HashMap<>(); config.put("service_description.name", "service_name_test"); ConfigUtil.setConfigs(config);// www . j ava2s .c o m ConfigUtil.addConfig("service_description.version", "1.0.2"); ConfigUtil.addConfig("cse.test.enabled", true); ConfigUtil.addConfig("cse.test.num", 10); AbstractConfiguration configuration = ConfigUtil.createDynamicConfig(); Assert.assertEquals(configuration.getString("service_description.name"), "service_name_test"); Assert.assertTrue(configuration.getBoolean("cse.test.enabled")); Assert.assertEquals(configuration.getInt("cse.test.num"), 10); }
From source file:org.apache.servicecomb.config.TestConfigUtil.java
@Test public void testConvertEnvVariable() { String someProperty = "cse_service_registry_address"; AbstractConfiguration config = new DynamicConfiguration(); config.addProperty(someProperty, "testing"); AbstractConfiguration result = ConfigUtil.convertEnvVariable(config); assertThat(result.getString("cse.service.registry.address"), equalTo("testing")); assertThat(result.getString("cse_service_registry_address"), equalTo("testing")); }
From source file:org.skb.util.types.composite.util.TSPropertyMap.java
public String loadFromFile(String fn) { try {//from w ww . j a v a 2 s.c o m AbstractConfiguration cfg; String prefix = ""; if (fn.endsWith(".ini")) { cfg = new INIConfiguration(fn); prefix = "tribe."; } else if (fn.endsWith(".xml")) cfg = new XMLConfiguration(fn); else if (fn.endsWith(".properties")) cfg = new PropertiesConfiguration(fn); else return "unknown configuration file format, use '.ini' or '.xml' or '.properties'"; File file = new File(fn); if (!file.canRead()) return "can't read configuration file <" + fn + ">"; Iterator<?> it; if (prefix != "") it = cfg.getKeys(prefix); else it = cfg.getKeys(); while (it.hasNext()) { String p = it.next().toString(); if (this.containsKey(p)) { String type = this.get(p, TSPropertyMap.pmValType).toString(); if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_STRING)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getString(p)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_BOOLEAN)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getBoolean(p, false)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_INTEGER)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getInteger(p, 0)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_DOUBLE)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getDouble(p)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_LONG)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getLong(p, 0)); // else // System.err.println("TSPropMap, loadfromfile, unknown type <"+type+"> for <"+p+">"); } } } catch (Exception e) { // ReportManager repMgr=ReportManager.getInstance(); // repMgr.reportErrorNoFile(e.toString()); } return null; }