Search in sources :

Example 26 with Properties

use of java.util.Properties in project camel by apache.

the class IOConverterTest method testToPropertiesFromReader.

public void testToPropertiesFromReader() throws Exception {
    Reader br = IOHelper.buffered(new StringReader("foo=123\nbar=456"));
    Properties p = IOConverter.toProperties(br);
    assertNotNull(p);
    assertEquals(2, p.size());
    assertEquals("123", p.get("foo"));
    assertEquals("456", p.get("bar"));
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Properties(java.util.Properties)

Example 27 with Properties

use of java.util.Properties in project camel by apache.

the class IOConverterTest method testToPropertiesFromFile.

public void testToPropertiesFromFile() throws Exception {
    Properties p = IOConverter.toProperties(new File("src/test/resources/log4j2.properties"));
    assertNotNull(p);
    assertTrue("Should be 8 or more properties, was " + p.size(), p.size() >= 8);
    String root = (String) p.get("rootLogger.level");
    assertNotNull(root);
    assertTrue(root.contains("INFO"));
}
Also used : Properties(java.util.Properties) File(java.io.File)

Example 28 with Properties

use of java.util.Properties in project camel by apache.

the class AbstractJsseParametersTest method createPropertiesPlaceholderAwareContext.

protected CamelContext createPropertiesPlaceholderAwareContext() throws Exception {
    Properties supplementalProperties = new Properties();
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    SecureRandom sr = null;
    try {
        sr = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException e) {
    // Ignore
    }
    SSLContext sslc = SSLContext.getInstance("TLS");
    sslc.init(null, null, null);
    SSLSocket socket = (SSLSocket) sslc.getSocketFactory().createSocket();
    supplementalProperties.setProperty("keyStoreParameters.type", KeyStore.getDefaultType());
    supplementalProperties.setProperty("keyStoreParameters.provider", ks.getProvider().getName());
    supplementalProperties.setProperty("keyManagersParameters.algorithm", KeyManagerFactory.getDefaultAlgorithm());
    supplementalProperties.setProperty("keyManagersParameters.provider", kmf.getProvider().getName());
    supplementalProperties.setProperty("trustManagersParameters.algorithm", TrustManagerFactory.getDefaultAlgorithm());
    supplementalProperties.setProperty("trustManagersParameters.provider", tmf.getProvider().getName());
    if (sr != null) {
        supplementalProperties.setProperty("secureRandomParameters.algorithm", "SHA1PRNG");
        supplementalProperties.setProperty("secureRandomParameters.provider", sr.getProvider().getName());
    }
    supplementalProperties.setProperty("sslContextParameters.provider", sslc.getProvider().getName());
    supplementalProperties.setProperty("cipherSuite.0", socket.getSupportedCipherSuites()[0]);
    // Have to skip this guy because he doesn't work with TLS as the SSLContext protocol
    String ssp = "";
    for (String protocol : socket.getSupportedProtocols()) {
        if (!"SSLv2Hello".equals(protocol)) {
            ssp = protocol;
            break;
        }
    }
    supplementalProperties.setProperty("secureSocketProtocol.0", ssp);
    return this.createPropertiesPlaceholderAwareContext(supplementalProperties);
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLSocket(javax.net.ssl.SSLSocket) SecureRandom(java.security.SecureRandom) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLContext(javax.net.ssl.SSLContext) Properties(java.util.Properties) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 29 with Properties

use of java.util.Properties in project camel by apache.

the class AbstractJsseParametersTest method createPropertiesPlaceholderAwareContext.

protected CamelContext createPropertiesPlaceholderAwareContext(Properties supplementalProperties) throws IOException {
    Properties properties = new Properties(supplementalProperties);
    properties.load(AbstractJsseParametersTest.class.getResourceAsStream("test.properties"));
    if (supplementalProperties != null) {
        Properties mergedProps = new Properties();
        Set<String> keys = new HashSet<String>();
        keys.addAll(properties.stringPropertyNames());
        keys.addAll(supplementalProperties.stringPropertyNames());
        for (String key : keys) {
            mergedProps.setProperty(key, properties.getProperty(key));
        }
        properties = mergedProps;
    }
    properties.store(new FileOutputStream("target/jsse-test.properties"), "Generated by " + AbstractJsseParametersTest.class.getName());
    PropertiesComponent pc = new PropertiesComponent();
    pc.setLocation("file:./target/jsse-test.properties");
    CamelContext context = new DefaultCamelContext();
    context.addComponent("properties", pc);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) HashSet(java.util.HashSet)

Example 30 with Properties

use of java.util.Properties in project camel by apache.

the class AbstractBraintreeTestSupport method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    final CamelContext context = super.createCamelContext();
    // read Braintree component configuration from TEST_OPTIONS_PROPERTIES
    final Properties properties = new Properties();
    try {
        properties.load(getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES));
    } catch (Exception e) {
        throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
    }
    Map<String, Object> options = new HashMap<>();
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        options.put(entry.getKey().toString(), entry.getValue());
    }
    addOptionIfMissing(options, "environment", "CAMEL_BRAINTREE_ENVIRONMENT");
    addOptionIfMissing(options, "merchantId", "CAMEL_BRAINTREE_MERCHANT_ID");
    addOptionIfMissing(options, "publicKey", "CAMEL_BRAINTREE_PUBLIC_KEY");
    addOptionIfMissing(options, "privateKey", "CAMEL_BRAINTREE_PRIVATE_KEY");
    final BraintreeConfiguration configuration = new BraintreeConfiguration();
    configuration.setHttpLogLevel(BraintreeLogHandler.DEFAULT_LOGGER_VERSION);
    configuration.setHttpLogName(BraintreeLogHandler.DEFAULT_LOGGER_NAME);
    IntrospectionSupport.setProperties(configuration, options);
    // add BraintreeComponent to Camel context
    final BraintreeComponent component = new BraintreeComponent(context);
    component.setConfiguration(configuration);
    context.addComponent("braintree", component);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Aggregations

Properties (java.util.Properties)9354 Test (org.junit.Test)3005 IOException (java.io.IOException)1277 Connection (java.sql.Connection)1179 File (java.io.File)1013 ResultSet (java.sql.ResultSet)860 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)819 PreparedStatement (java.sql.PreparedStatement)791 InputStream (java.io.InputStream)614 FileInputStream (java.io.FileInputStream)598 HashMap (java.util.HashMap)475 Map (java.util.Map)387 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)387 ArrayList (java.util.ArrayList)371 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)321 SQLException (java.sql.SQLException)308 Before (org.junit.Before)272 AttributesFactory (org.apache.geode.cache.AttributesFactory)245 InitialContext (javax.naming.InitialContext)214 Configuration (org.apache.hadoop.conf.Configuration)187