List of usage examples for org.apache.commons.configuration AbstractConfiguration setProperty
public void setProperty(String key, Object value)
From source file:com.netflix.zuul.StartServer.java
void initCassandra() throws Exception { if (cassandraEnabled.get()) { final AbstractConfiguration cassandraProperties = ConfigurationManager.getConfigInstance(); /* defaults */ cassandraProperties.setProperty(DEFAULT_NFASTYANAX_READCONSISTENCY, DynamicPropertyFactory.getInstance() .getStringProperty(DEFAULT_NFASTYANAX_READCONSISTENCY, "CL_ONE").get()); cassandraProperties.setProperty(DEFAULT_NFASTYANAX_WRITECONSISTENCY, DynamicPropertyFactory.getInstance() .getStringProperty("zuul.cassandra.default.nfastyanax.writeConsistency", "CL_ONE") .get());//w w w. jav a2 s. c om cassandraProperties.setProperty(DEFAULT_NFASTYANAX_SOCKETTIMEOUT, DynamicPropertyFactory.getInstance() .getStringProperty("zuul.cassandra.default.nfastyanax.socketTimeout", "2000").get()); cassandraProperties.setProperty(DEFAULT_NFASTYANAX_MAXCONNSPERHOST, DynamicPropertyFactory.getInstance() .getStringProperty("zuul.cassandra.default.nfastyanax.maxConnsPerHost", "3").get()); cassandraProperties.setProperty(DEFAULT_NFASTYANAX_MAXTIMEOUTWHENEXHAUSTED, DynamicPropertyFactory.getInstance() .getStringProperty("zuul.cassandra.default.nfastyanax.maxTimeoutWhenExhausted", "2000") .get()); cassandraProperties.setProperty(DEFAULT_NFASTYANAX_MAXFAILOVERCOUNT, DynamicPropertyFactory.getInstance() .getStringProperty("zuul.cassandra.default.nfastyanax.maxFailoverCount", "1").get()); cassandraProperties.setProperty(DEFAULT_NFASTYANAX_FAILOVERWAITTIME, DynamicPropertyFactory.getInstance() .getStringProperty("zuul.cassandra.default.nfastyanax.failoverWaitTime", "0").get()); LOG.info("Getting AstyanaxContext"); Keyspace keyspace = getZuulCassKeyspace(); LOG.info("Initializing Cassandra ZuulFilterDAO"); ZuulFilterDAO dao = new ZuulFilterDAOCassandra(keyspace); LOG.info("Starting ZuulFilter Poller"); ZuulFilterPoller.start(dao); } }
From source file:com.netflix.niws.client.http.SecureAcceptAllGetTest.java
@Test public void testNegativeAcceptAllSSLSocketFactoryCannotWorkWithTrustStore() throws Exception { // test config exception happens before we even try to connect to anything AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = "GetPostSecureTest" + ".testNegativeAcceptAllSSLSocketFactoryCannotWorkWithTrustStore"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, TEST_FILE_TS.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, SecureGetTest.PASSWORD); boolean foundCause = false; try {/* ww w.j av a2 s . co m*/ ClientFactory.getNamedClient(name); } catch (Throwable t) { while (t != null && !foundCause) { if (t instanceof IllegalArgumentException && t.getMessage() .startsWith("Invalid value associated with property:CustomSSLSocketFactoryClassName")) { foundCause = true; break; } t = t.getCause(); } } assertTrue(foundCause); }
From source file:com.netflix.niws.client.http.SecureGetTest.java
@Test public void testSunnyDay() throws Exception { AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = "GetPostSecureTest" + ".testSunnyDay"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT1)); cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, FILE_KS1.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, PASSWORD); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD); RestClient rc = (RestClient) ClientFactory.getNamedClient(name); testServer1.accept();/*from w w w . j a v a 2 s . c o m*/ URI getUri = new URI(SERVICE_URI1 + "test/"); HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build(); HttpResponse response = rc.execute(request); assertEquals(200, response.getStatus()); }
From source file:com.netflix.niws.client.http.SecureGetTest.java
@Test public void testSunnyDayNoClientAuth() throws Exception { AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = "GetPostSecureTest" + ".testSunnyDayNoClientAuth"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2)); cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS2.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD); RestClient rc = (RestClient) ClientFactory.getNamedClient(name); testServer2.accept();//ww w .j a va 2 s . co m URI getUri = new URI(SERVICE_URI2 + "test/"); HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build(); HttpResponse response = rc.execute(request); assertEquals(200, response.getStatus()); }
From source file:com.netflix.niws.client.http.SecureGetTest.java
@Test public void testClientRejectsWrongServer() throws Exception { AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = "GetPostSecureTest" + ".testClientRejectsWrongServer"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2)); cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath()); // <-- cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD); RestClient rc = (RestClient) ClientFactory.getNamedClient(name); testServer2.accept();//from www.j ava 2 s .co m URI getUri = new URI(SERVICE_URI2 + "test/"); HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build(); try { rc.execute(request); fail("expecting ssl hostname validation error"); } catch (ClientHandlerException che) { assertTrue(che.getMessage().indexOf("peer not authenticated") > -1); } }
From source file:com.netflix.niws.client.http.SecureGetTest.java
@Test public void testFailsWithHostNameValidationOn() throws Exception { AbstractConfiguration cm = ConfigurationManager.getConfigInstance(); String name = "GetPostSecureTest" + ".testFailsWithHostNameValidationOn"; String configPrefix = name + "." + "ribbon"; cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT1)); cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "true"); // <-- cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true"); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, FILE_KS1.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, PASSWORD); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath()); cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD); RestClient rc = (RestClient) ClientFactory.getNamedClient(name); testServer1.accept();/*from ww w . ja v a 2s .c om*/ URI getUri = new URI(SERVICE_URI1 + "test/"); MultivaluedMapImpl params = new MultivaluedMapImpl(); params.add("name", "test"); HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build(); try { rc.execute(request); fail("expecting ssl hostname validation error"); } catch (ClientHandlerException che) { assertTrue(che.getMessage().indexOf("hostname in certificate didn't match") > -1); } }
From source file:com.zxy.commons.hystrix.HystrixConfigurationManager.java
/** * hystirx init/* www .ja va2s.co m*/ * * @return Void */ // @Scope(value = "singleton") // @HystrixCommand(commandProperties = { // @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500") // }, // threadPoolProperties = { // @HystrixProperty(name = "coreSize", value = "30"), // @HystrixProperty(name = "maxQueueSize", value = "101"), // @HystrixProperty(name = "keepAliveTimeMinutes", value = "2"), // @HystrixProperty(name = "queueSizeRejectionThreshold", value = "15"), // @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"), // @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440") // }) @Bean public AbstractConfiguration configuration() { // http://blog.csdn.net/zheng0518/article/details/51713900 AbstractConfiguration configuration = ConfigurationManager.getConfigInstance(); // groupgroup. getClass().getSimpleName(); // configuration.setProperty("groupKey", value); // ??? // configuration.setProperty("commandKey", value); String straegy = properties.getEnv().getProperty(HystrixProperties.EXECUTION_ISOLATION_STRATEGY, "THREAD"); configuration.setProperty(HystrixProperties.EXECUTION_ISOLATION_STRATEGY, straegy); // . 1000 // THREAD??. SEMAPHORE????? // retry99meantime+avg meantime. retry99.5meantime String isolationTimeoutInmilliseconds = properties.getEnv() .getProperty(HystrixProperties.ISOLATION_TIMEOUT_INMILLISECONDS, "1000"); configuration.setProperty(HystrixProperties.ISOLATION_TIMEOUT_INMILLISECONDS, isolationTimeoutInmilliseconds); // coreSize. 10 qps*99meantime+breathing room String coreSize = properties.getEnv().getProperty(HystrixProperties.CORE_SIZE, String.valueOf(Runtime.getRuntime().availableProcessors() * 2)); configuration.setProperty(HystrixProperties.CORE_SIZE, coreSize); // ???coreSize String maximumSize = properties.getEnv().getProperty(HystrixProperties.MAXIMUM_SIZE, coreSize); configuration.setProperty(HystrixProperties.MAXIMUM_SIZE, maximumSize); // . -1 SynchronizeQueueLinkedBlockingQueue String maxQueueSize = properties.getEnv().getProperty(HystrixProperties.MAX_QUEUE_SIZE, "-1"); configuration.setProperty(HystrixProperties.MAX_QUEUE_SIZE, maxQueueSize); // 1 String keepAliveTimeMinutes = properties.getEnv().getProperty(HystrixProperties.KEEP_ALIVETIME_MINUTES, "1"); configuration.setProperty(HystrixProperties.KEEP_ALIVETIME_MINUTES, keepAliveTimeMinutes); // maxQueueSize????????5 String queueSizeRejectionThreshold = properties.getEnv() .getProperty(HystrixProperties.QUEUE_SIZE_REJECTION_THRESHOLD, "5"); configuration.setProperty(HystrixProperties.QUEUE_SIZE_REJECTION_THRESHOLD, queueSizeRejectionThreshold); // ?. true String executionTimeoutEnabled = properties.getEnv() .getProperty(HystrixProperties.EXECUTION_TIMEOUT_ENABLED, "true"); configuration.setProperty(HystrixProperties.EXECUTION_TIMEOUT_ENABLED, executionTimeoutEnabled); // ?(interrupt) HystrixCommand.run() String executionInterruptOnTimeout = properties.getEnv() .getProperty(HystrixProperties.EXECUTION_INTERRUPTONTIMEOUT, "true"); configuration.setProperty(HystrixProperties.EXECUTION_INTERRUPTONTIMEOUT, executionInterruptOnTimeout); // 1020??. 20 String circuitBreakerRequestVolumeThreshold = properties.getEnv() .getProperty(HystrixProperties.CIRCUITBREAKER_REQUEST_VOLUME_THRESHOLD, "20"); configuration.setProperty(HystrixProperties.CIRCUITBREAKER_REQUEST_VOLUME_THRESHOLD, circuitBreakerRequestVolumeThreshold); // 10???,???. 5000 String circuitBreakerSleepWindowInMilliseconds = properties.getEnv() .getProperty(HystrixProperties.CIRCUITBREAKER_SLEEP_WINDOW_INMILLISECONDS, "5000"); configuration.setProperty(HystrixProperties.CIRCUITBREAKER_SLEEP_WINDOW_INMILLISECONDS, circuitBreakerSleepWindowInMilliseconds); // ?. 50 ????? String circuitBreakerErrorThresholdPercentage = properties.getEnv() .getProperty(HystrixProperties.CIRCUITBREAKER_ERROR_THRESHOLD_PERCENTAGE, "50"); configuration.setProperty(HystrixProperties.CIRCUITBREAKER_ERROR_THRESHOLD_PERCENTAGE, circuitBreakerErrorThresholdPercentage); // ? ?true String circuitBreakerForceClosed = properties.getEnv() .getProperty(HystrixProperties.CIRCUITBREAKER_FORCE_CLOSED, "false"); configuration.setProperty(HystrixProperties.CIRCUITBREAKER_FORCE_CLOSED, circuitBreakerForceClosed); // ??true String circuitBreakerEnabled = properties.getEnv().getProperty(HystrixProperties.CIRCUITBREAKER_ENABLED, "true"); configuration.setProperty(HystrixProperties.CIRCUITBREAKER_ENABLED, circuitBreakerEnabled); // ?request-scopetrue String requestCacheEnabled = properties.getEnv().getProperty(HystrixProperties.REQUESTCACHE_ENABLED, "true"); configuration.setProperty(HystrixProperties.REQUESTCACHE_ENABLED, requestCacheEnabled); // HystrixCommand??HystrixRequestLog String requestLogEnabled = properties.getEnv().getProperty(HystrixProperties.REQUESTLOG_ENABLED, "true"); configuration.setProperty(HystrixProperties.REQUESTLOG_ENABLED, requestLogEnabled); /*// ?10metrics.rollingStats.timeInMilliseconds String metricsRollingStatsNumBuckets = properties.getEnv().getProperty(HystrixProperties.METRICS_ROLLINGSTATS_NUMBUCKETS, "10"); configuration.setProperty(HystrixProperties.METRICS_ROLLINGSTATS_NUMBUCKETS, metricsRollingStatsNumBuckets); // ?10s String metricsRollingStatsTimeInMilliseconds = properties.getEnv().getProperty(HystrixProperties.METRICS_ROLLINGSTATS_TIMEINMILLISECONDS, "10000"); configuration.setProperty(HystrixProperties.METRICS_ROLLINGSTATS_TIMEINMILLISECONDS, metricsRollingStatsTimeInMilliseconds); // ??50%,90%true String metricsRollingPercentileEnabled = properties.getEnv().getProperty(HystrixProperties.METRICS_ROLLINGPERCENTILE_ENABLED, "true"); configuration.setProperty(HystrixProperties.METRICS_ROLLINGPERCENTILE_ENABLED, metricsRollingPercentileEnabled);*/ return configuration; }
From source file:gov.nih.nci.security.upt.forms.SystemConfigurationForm.java
public void buildDBObject(UserProvisioningManager userProvisioningManager) throws Exception { AbstractConfiguration dataConfig = ConfigurationHelper.getConfiguration(); Iterator entries = request.getParameterMap().entrySet().iterator(); String prevExpiryVal = null;// w ww . ja v a 2 s. co m String[] currExpiryVal = null; while (entries.hasNext()) { Entry thisEntry = (Entry) entries.next(); Object key = thisEntry.getKey(); String keyString = (String) thisEntry.getKey(); if (keyString != null && keyString.equalsIgnoreCase("PASSWORD_EXPIRY_DAYS")) { if (dataConfig.getProperty(keyString) != null) { prevExpiryVal = (String) dataConfig.getProperty(keyString); currExpiryVal = (String[]) thisEntry.getValue(); } } if (dataConfig.getProperty((String) thisEntry.getKey()) != null) { dataConfig.setProperty((String) thisEntry.getKey(), thisEntry.getValue()); } Object value = thisEntry.getValue(); } if (prevExpiryVal != null && currExpiryVal[0] != null) { if (!prevExpiryVal.equalsIgnoreCase(currExpiryVal[0])) { List<User> list = userProvisioningManager.getUsers(); if (list != null) { Iterator UserListIterator = list.iterator(); while (UserListIterator.hasNext()) { User user = (User) UserListIterator.next(); if (user != null) { // compare and update the expiry dates here int dateDiff = Integer.parseInt(currExpiryVal[0]) - Integer.parseInt(prevExpiryVal); user.setPasswordExpiryDate(DateUtils.addDays(user.getPasswordExpiryDate(), dateDiff)); userProvisioningManager.modifyUser(user); } } } } } }
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;//from ww w.j av a 2s. c om } 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:netflix.archaius.SampleApplication.java
/** * SampleApplication entrypoint//from w w w . j a v a2s . c o m * @param args * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws InterruptedException, IOException { //@SuppressWarnings(value = {"unused" }) new SampleApplication(); // Step 1. // Create a Source of Configuration // Here we use a simple ConcurrentMapConfiguration // You can use your own, or use of the pre built ones including JDBCConfigurationSource // which lets you load properties from any RDBMS AbstractConfiguration myConfiguration = new ConcurrentMapConfiguration(); myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1"); myConfiguration.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Gautemala1"); // STEP 2: Optional. Dynamic Runtime property change option // We would like to utilize the benefits of obtaining dynamic property // changes // initialize the DynamicPropertyFactory with our configuration source DynamicPropertyFactory.initWithConfigurationSource(myConfiguration); // STEP 3: Optional. Option to inspect and modify properties using JConsole // We would like to inspect properties via JMX JConsole and potentially // update // these properties too // Register the MBean // // This can be also achieved automatically by setting "true" to // system property "archaius.dynamicPropertyFactory.registerConfigWithJMX" configMBean = ConfigJMXManager.registerConfigMbean(myConfiguration); // once this application is launched, launch JConsole and navigate to // the // Config MBean (under the MBeans tab) System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties"); System.out.println( "To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole"); SampleBean sampleBean = new SampleBean(); System.out.println("SampleBean:" + sampleBean); System.out.println(sampleBean.getName()); System.setProperty("archaius.fixedDelayPollingScheduler.initialDelayMills", "100"); System.setProperty("archaius.fixedDelayPollingScheduler.delayMills", "100"); // System.setProperty("archaius.configurationSource.defaultFileName", "log4j.properties"); // ConfigurationManager.loadCascadedPropertiesFromResources("log4j"); FixedDelayPollingScheduler f = new FixedDelayPollingScheduler(100, 100, true); // create a property whose value is type long and use 1000 as the default // if the property is not defined System.setProperty("archaius.fixedDelayPollingScheduler.initialDelayMills", "100"); System.setProperty("archaius.fixedDelayPollingScheduler.delayMills", "100"); System.setProperty("archaius.configurationSource.defaultFileName", "log4j.properties"); ConfigurationManager.loadCascadedPropertiesFromResources("log4j"); // create a property whose value is type long and use 1000 as the default // if the property is not defined DynamicLongProperty timeToWait = DynamicPropertyFactory.getInstance().getLongProperty("lock.waitTime", 1000); ReentrantLock lock = new ReentrantLock(); // ... while (true) { lock.tryLock(timeToWait.get(), TimeUnit.MILLISECONDS); // timeToWait.get() returns up-to-date value of the property System.out.println("??" + timeToWait.get()); Thread.sleep(1000); // AbstractConfiguration myConfiguration = new ConcurrentMapConfiguration(); // myConfiguration.setProperty("lock.waitTime", 11); // DynamicPropertyFactory.initWithConfigurationSource(myConfiguration); // System.out.println( "??"+timeToWait.get()); } }