use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class Config method properties.
@Produces
@ApplicationScoped
@Named("properties")
PropertiesComponent properties() {
PropertiesComponent component = new PropertiesComponent();
component.setLocation("classpath:jms.properties");
return component;
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class JavaScriptPropertiesFunctionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
pc.setLocation("org/apache/camel/builder/script/myproperties.properties");
from("direct:start").setHeader("myHeader").javaScript("properties.resolve(request.headers.get('foo'))").to("mock:result");
}
};
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class CamelSpringPropertiesLocationElementTest method testPropertiesLocationElement.
@Test
public void testPropertiesLocationElement() throws Exception {
mock.expectedHeaderReceived("property-1", "property-value-1");
mock.expectedHeaderReceived("property-2", "property-value-2");
mock.expectedHeaderReceived("property-3", "property-value-3");
PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
assertNotNull("Properties component not defined", pc);
List<PropertiesLocation> locations = pc.getLocations();
assertNotNull(locations);
assertEquals("Properties locations", 4, locations.size());
producer.sendBody("direct:start", null);
mock.assertIsSatisfied();
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class PropertiesComponentAutoConfiguration method configurePropertiesComponent.
@Lazy
@Bean(name = "properties-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(PropertiesComponent.class)
public PropertiesComponent configurePropertiesComponent(CamelContext camelContext, PropertiesComponentConfiguration configuration) throws Exception {
PropertiesComponent component = new PropertiesComponent();
component.setCamelContext(camelContext);
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Object value = entry.getValue();
Class<?> paramClass = value.getClass();
if (paramClass.getName().endsWith("NestedConfiguration")) {
Class nestedClass = null;
try {
nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
HashMap<String, Object> nestedParameters = new HashMap<>();
IntrospectionSupport.getProperties(value, nestedParameters, null, false);
Object nestedProperty = nestedClass.newInstance();
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
entry.setValue(nestedProperty);
} catch (NoSuchFieldException e) {
}
}
}
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
return component;
}
use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.
the class BaseNettyTest method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
context.addComponent("properties", new PropertiesComponent("ref:prop"));
return context;
}
Aggregations