Search in sources :

Example 11 with Properties

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

the class DefaultPropertiesResolver method loadPropertiesFromClasspath.

protected Properties loadPropertiesFromClasspath(CamelContext context, boolean ignoreMissingLocation, PropertiesLocation location) throws IOException {
    Properties answer = new Properties();
    String path = location.getPath();
    InputStream is = context.getClassResolver().loadResourceAsStream(path);
    Reader reader = null;
    if (is == null) {
        if (!ignoreMissingLocation && !location.isOptional()) {
            throw new FileNotFoundException("Properties file " + path + " not found in classpath");
        }
    } else {
        try {
            if (propertiesComponent.getEncoding() != null) {
                reader = new BufferedReader(new InputStreamReader(is, propertiesComponent.getEncoding()));
                answer.load(reader);
            } else {
                answer.load(is);
            }
        } finally {
            IOHelper.close(reader, is);
        }
    }
    return answer;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Properties(java.util.Properties)

Example 12 with Properties

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

the class Activator method loadProperties.

protected static Properties loadProperties(URL url) {
    Properties properties = new Properties();
    BufferedInputStream reader = null;
    try {
        reader = IOHelper.buffered(url.openStream());
        properties.load(reader);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOHelper.close(reader, "properties", LOG);
    }
    return properties;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Example 13 with Properties

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

the class ComponentDiscoveryTest method testComponentDiscovery.

@Test
public void testComponentDiscovery() throws Exception {
    CamelContext context = new DefaultCamelContext();
    SortedMap<String, Properties> map = CamelContextHelper.findComponents(context);
    assertNotNull("Should never return null", map);
    assertTrue("Component map should never be empty", !map.isEmpty());
    String[] expectedComponentNames = { "file", "vm" };
    for (String expectedName : expectedComponentNames) {
        Properties properties = map.get(expectedName);
        assertTrue("Component map contain component: " + expectedName, properties != null);
    }
    Set<Map.Entry<String, Properties>> entries = map.entrySet();
    for (Map.Entry<String, Properties> entry : entries) {
        LOG.info("Found component " + entry.getKey() + " with properties: " + entry.getValue());
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Properties(java.util.Properties) Map(java.util.Map) SortedMap(java.util.SortedMap) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 14 with Properties

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

the class PropertiesAvailableEverywhereTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();
    final Properties properties = new Properties();
    properties.put("foo", "bar");
    PropertiesComponent pc = camelContext.getComponent("properties", PropertiesComponent.class);
    pc.setLocations(new String[0]);
    pc.setPropertiesResolver(new PropertiesResolver() {

        @Override
        public Properties resolveProperties(CamelContext context, boolean ignoreMissingLocation, List<PropertiesLocation> locations) {
            return properties;
        }
    });
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) PropertiesResolver(org.apache.camel.component.properties.PropertiesResolver) PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) Properties(java.util.Properties) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 15 with Properties

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

the class ManagedCamelContextUpdateRoutesWithPropertyPlaceholdersFromXmlPTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    props = new Properties();
    props.put("somewhere", "mock:changed");
    props.put("theBar", "mock:bar");
    CamelContext context = super.createCamelContext();
    PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
    pc.setLocations(new String[0]);
    pc.setOverrideProperties(props);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) Properties(java.util.Properties) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

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