Search in sources :

Example 36 with PropertiesComponent

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;
}
Also used : PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 37 with PropertiesComponent

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");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 38 with PropertiesComponent

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();
}
Also used : PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Test(org.junit.Test)

Example 39 with PropertiesComponent

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;
}
Also used : HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 40 with PropertiesComponent

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Aggregations

PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)83 CamelContext (org.apache.camel.CamelContext)35 Properties (java.util.Properties)17 ApplicationScoped (javax.enterprise.context.ApplicationScoped)12 Produces (javax.enterprise.inject.Produces)12 Named (javax.inject.Named)12 RouteBuilder (org.apache.camel.builder.RouteBuilder)11 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)8 PropertiesLocation (org.apache.camel.component.properties.PropertiesLocation)7 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)6 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Component (org.apache.camel.Component)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Exchange (org.apache.camel.Exchange)2