Java Code Examples for org.apache.commons.configuration.AbstractConfiguration#setProperty()

The following examples show how to use org.apache.commons.configuration.AbstractConfiguration#setProperty() . 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: SecureGetTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@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(testServer2.getPort()));
	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();

	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());
}
 
Example 2
Source File: ArchaiusPropertyResolverTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void mapFromPrefixedKeys() {
    final String prefix = "client.ribbon." + testName.getMethodName();

    final AbstractConfiguration config = ConfigurationManager.getConfigInstance();

    config.setProperty(prefix + ".a", "1");
    config.setProperty(prefix + ".b", "2");
    config.setProperty(prefix + ".c", "3");

    final ArchaiusPropertyResolver resolver = ArchaiusPropertyResolver.INSTANCE;

    final Map<String, String> map = new TreeMap<>();

    resolver.forEach(prefix, map::put);

    final Map<String, String> expected = new TreeMap<>();
    expected.put("a", "1");
    expected.put("b", "2");
    expected.put("c", "3");

    Assert.assertEquals(expected, map);
}
 
Example 3
Source File: TurbineInstanceDiscovery.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
public static void registerClusters(Collection<String> clusterNames,
                                    String instanceUrlSuffix) {
    final AbstractConfiguration configurationManager = ConfigurationManager.getConfigInstance();
    configurationManager.setProperty(InstanceDiscovery.TURBINE_AGGREGATOR_CLUSTER_CONFIG,
            Joiner.on(',').join(clusterNames));
    configurationManager.setProperty("turbine.instanceUrlSuffix", instanceUrlSuffix);
    final ClusterMonitorFactory<?> clusterMonitorFactory = PluginsFactory.getClusterMonitorFactory();
    if (clusterMonitorFactory != null) {
        try {
            clusterMonitorFactory.initClusterMonitors();
        } catch (Exception err) {
            LOGGER.error("Trouble initializing cluster monitors", err);
        }
    }
}
 
Example 4
Source File: SecureAcceptAllGetTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@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." + testName.getMethodName();

    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 {
        ClientFactory.getNamedClient(name);
    } catch(Throwable t){
         while (t != null && ! foundCause){
             if (t instanceof IllegalArgumentException && t.getMessage().startsWith("Invalid value for property:CustomSSLSocketFactoryClassName")){
                 foundCause = true;
                 break;
             }
             t = t.getCause();
         }
    }

    assertTrue(foundCause);
}
 
Example 5
Source File: SecureGetTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@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(testServer1.getPort()));
	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();

	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());
}
 
Example 6
Source File: SecureGetTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@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(testServer2.getPort()));
	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();

	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);
	}
}
 
Example 7
Source File: SecureGetTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@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(testServer2.getPort()));
	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();

	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);
	}
}
 
Example 8
Source File: SecureRestClientKeystoreTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetKeystoreWithClientAuth() throws Exception{

	// jks format
	byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
	byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);

	File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
	File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");

	FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
       try {
           keystoreFileOut.write(dummyKeystore);
       } finally {
           keystoreFileOut.close();
       }

	FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
       try {
           truststoreFileOut.write(dummyTruststore);
       } finally {
           truststoreFileOut.close();
       }

	AbstractConfiguration cm = ConfigurationManager.getConfigInstance();

	String name = this.getClass().getName() + ".test1";

	String configPrefix = name + "." + "ribbon";

	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.IsSecure, "true");
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.IsClientAuthRequired, "true");
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.KeyStorePassword, "changeit");
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.TrustStore, tempTruststore.getAbsolutePath());
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.TrustStorePassword, "changeit");

	RestClient client = (RestClient) ClientFactory.getNamedClient(name);

	KeyStore keyStore = client.getKeyStore();

	Certificate cert = keyStore.getCertificate("ribbon_key");

	assertNotNull(cert);

}
 
Example 9
Source File: SecureRestClientKeystoreTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetKeystoreWithNoClientAuth() throws Exception{

	// jks format
	byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
	byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);

	File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
	File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");

	FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
       try {
           keystoreFileOut.write(dummyKeystore);
       } finally {
           keystoreFileOut.close();
       }

	FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
       try {
           truststoreFileOut.write(dummyTruststore);
       } finally {
           truststoreFileOut.close();
       }

	AbstractConfiguration cm = ConfigurationManager.getConfigInstance();

	String name = this.getClass().getName() + ".test2";

	String configPrefix = name + "." + "ribbon";

	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.IsSecure, "true");
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
	cm.setProperty(configPrefix + "." +  CommonClientConfigKey.KeyStorePassword, "changeit");

	RestClient client = (RestClient) ClientFactory.getNamedClient(name);

	KeyStore keyStore = client.getKeyStore();

	Certificate cert = keyStore.getCertificate("ribbon_key");

	assertNotNull(cert);
}
 
Example 10
Source File: SecureAcceptAllGetTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Test
public void testPositiveAcceptAllSSLSocketFactory() throws Exception{

    // test connection succeeds connecting to a random SSL endpoint with allow all SSL factory

    AbstractConfiguration cm = ConfigurationManager.getConfigInstance();

    String name = "GetPostSecureTest." + testName.getMethodName();

    String configPrefix = name + "." + "ribbon";

    cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory");

    RestClient rc = (RestClient) ClientFactory.getNamedClient(name);

    TEST_SERVER.accept();

    URI getUri = new URI(TEST_SERVICE_URI + "test/");
    HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
    HttpResponse response = rc.execute(request);
    assertEquals(200, response.getStatus());
}
 
Example 11
Source File: TenacityPropertyRegister.java    From tenacity with Apache License 2.0 4 votes vote down vote up
public static void registerCircuitForceReset(TenacityPropertyKey key) {
    final AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance();
    configInstance.setProperty(circuitBreakerForceOpen(key), false);
    configInstance.setProperty(circuitBreakerForceClosed(key), false);
}
 
Example 12
Source File: TenacityPropertyRegister.java    From tenacity with Apache License 2.0 4 votes vote down vote up
private void registerConfiguration(TenacityPropertyKey key,
                                   TenacityConfiguration configuration,
                                   AbstractConfiguration configInstance) {
    configInstance.setProperty(
            executionIsolationThreadTimeoutInMilliseconds(key),
            configuration.getExecutionIsolationThreadTimeoutInMillis());

    configInstance.setProperty(
            circuitBreakerRequestVolumeThreshold(key),
            configuration.getCircuitBreaker().getRequestVolumeThreshold());

    configInstance.setProperty(
            circuitBreakerSleepWindowInMilliseconds(key),
            configuration.getCircuitBreaker().getSleepWindowInMillis());

    configInstance.setProperty(
            circuitBreakerErrorThresholdPercentage(key),
            configuration.getCircuitBreaker().getErrorThresholdPercentage());

    configInstance.setProperty(
            circuitBreakermetricsRollingStatsNumBuckets(key),
            configuration.getCircuitBreaker().getMetricsRollingStatisticalWindowBuckets());

    configInstance.setProperty(
            circuitBreakermetricsRollingStatsTimeInMilliseconds(key),
            configuration.getCircuitBreaker().getMetricsRollingStatisticalWindowInMilliseconds());

    configInstance.setProperty(
            threadpoolCoreSize(key),
            configuration.getThreadpool().getThreadPoolCoreSize());

    configInstance.setProperty(
            threadpoolKeepAliveTimeMinutes(key),
            configuration.getThreadpool().getKeepAliveTimeMinutes());

    configInstance.setProperty(
            threadpoolMaxQueueSize(key),
            configuration.getThreadpool().getMaxQueueSize());

    configInstance.setProperty(
            threadpoolQueueSizeRejectionThreshold(key),
            configuration.getThreadpool().getQueueSizeRejectionThreshold());

    configInstance.setProperty(
            threadpoolMetricsRollingStatsNumBuckets(key),
            configuration.getThreadpool().getMetricsRollingStatisticalWindowBuckets());

    configInstance.setProperty(
            threadpoolMetricsRollingStatsTimeInMilliseconds(key),
            configuration.getThreadpool().getMetricsRollingStatisticalWindowInMilliseconds());

    configInstance.setProperty(
            semaphoreMaxConcurrentRequests(key),
            configuration.getSemaphore().getMaxConcurrentRequests());

    configInstance.setProperty(
            semaphoreFallbackMaxConcurrentRequests(key),
            configuration.getSemaphore().getFallbackMaxConcurrentRequests());

    if (configuration.hasExecutionIsolationStrategy()) {
        configInstance.setProperty(
                executionIsolationStrategy(key),
                configuration.getExecutionIsolationStrategy());
    }
}
 
Example 13
Source File: TenacityTestRule.java    From tenacity with Apache License 2.0 4 votes vote down vote up
private void setup() {
    resetStreams();
    Hystrix.reset();
    final AbstractConfiguration configuration = ConfigurationManager.getConfigInstance();
    configuration.setProperty("hystrix.command.default.metrics.healthSnapshot.intervalInMilliseconds", "100");
}
 
Example 14
Source File: ZuulFiltersModuleIntegTest.java    From zuul with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void before() {
    AbstractConfiguration configuration = ConfigurationManager.getConfigInstance();
    configuration.setProperty("zuul.filters.locations", "inbound,outbound,endpoint");
    configuration.setProperty("zuul.filters.packages", "com.netflix.zuul.init,com.netflix.zuul.init2");
}