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;
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations