use of org.apache.camel.component.properties.PropertiesLocation in project camel by apache.
the class BlueprintPropertiesLocationElementOptionalTest method testPropertiesLocationElement.
@Test
public void testPropertiesLocationElement() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedHeaderReceived("property-1", "property-value-1");
mock.expectedHeaderReceived("property-2", "property-value-2");
mock.expectedHeaderReceived("cm", "cm-value");
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
assertNotNull("Properties component not defined", pc);
List<PropertiesLocation> locations = pc.getLocations();
assertNotNull(locations);
assertEquals("Properties locations", 3, locations.size());
template.sendBody("direct:start", null);
mock.assertIsSatisfied();
}
use of org.apache.camel.component.properties.PropertiesLocation in project camel by apache.
the class BlueprintPropertiesLocationElementTest method testPropertiesLocationElement.
@Test
public void testPropertiesLocationElement() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedHeaderReceived("property-1", "property-value-1");
mock.expectedHeaderReceived("property-2", "property-value-2");
mock.expectedHeaderReceived("cm", "cm-value");
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
assertNotNull("Properties component not defined", pc);
List<PropertiesLocation> locations = pc.getLocations();
assertNotNull(locations);
assertEquals("Properties locations", 3, locations.size());
template.sendBody("direct:start", null);
mock.assertIsSatisfied();
}
use of org.apache.camel.component.properties.PropertiesLocation in project camel by apache.
the class CamelContextFactoryBean method initPropertyPlaceholder.
@Override
protected void initPropertyPlaceholder() throws Exception {
super.initPropertyPlaceholder();
Map<String, BridgePropertyPlaceholderConfigurer> beans = applicationContext.getBeansOfType(BridgePropertyPlaceholderConfigurer.class);
if (beans.size() == 1) {
// setup properties component that uses this beans
BridgePropertyPlaceholderConfigurer configurer = beans.values().iterator().next();
String id = beans.keySet().iterator().next();
LOG.info("Bridging Camel and Spring property placeholder configurer with id: " + id);
// get properties component
PropertiesComponent pc = (PropertiesComponent) getContext().getComponent("properties", false);
if (pc == null) {
// do not auto create the component as spring autowrire by constructor causes a side effect when using bridge
pc = new PropertiesComponent();
getContext().addComponent("properties", pc);
}
// use the spring system properties mode which has a different value than Camel may have
pc.setSystemPropertiesMode(configurer.getSystemPropertiesMode());
// replace existing resolver with us
configurer.setResolver(pc.getPropertiesResolver());
configurer.setParser(pc.getPropertiesParser());
// use the bridge to handle the resolve and parsing
pc.setPropertiesResolver(configurer);
pc.setPropertiesParser(configurer);
// and update locations to have our as ref first
List<PropertiesLocation> locations = new ArrayList<>(pc.getLocations());
locations.add(0, new PropertiesLocation("ref", id));
pc.setLocations(locations);
} else if (beans.size() > 1) {
LOG.warn("Cannot bridge Camel and Spring property placeholders, as exact only 1 bean of type BridgePropertyPlaceholderConfigurer" + " must be defined, was {} beans defined.", beans.size());
}
}
Aggregations