Search in sources :

Example 71 with PropertiesComponent

use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.

the class CamelContextHelper method lookupPropertiesComponent.

/**
     * Lookup the {@link org.apache.camel.component.properties.PropertiesComponent} from the {@link org.apache.camel.CamelContext}.
     * <p/>
     * @param camelContext the camel context
     * @param autoCreate whether to automatic create a new default {@link org.apache.camel.component.properties.PropertiesComponent} if no custom component
     *                   has been configured.
     * @return the properties component, or <tt>null</tt> if none has been defined, and auto create is <tt>false</tt>.
     */
public static Component lookupPropertiesComponent(CamelContext camelContext, boolean autoCreate) {
    // no existing properties component so lookup and add as component if possible
    PropertiesComponent answer = (PropertiesComponent) camelContext.hasComponent("properties");
    if (answer == null) {
        // lookup what is stored under properties, as it may not be the Camel properties component
        Object found = camelContext.getRegistry().lookupByName("properties");
        if (found != null && found instanceof PropertiesComponent) {
            answer = (PropertiesComponent) found;
            camelContext.addComponent("properties", answer);
        }
    }
    if (answer == null && autoCreate) {
        // create a default properties component to be used as there may be default values we can use
        LOG.info("No existing PropertiesComponent has been configured, creating a new default PropertiesComponent with name: properties");
        // do not auto create using getComponent as spring auto-wire by constructor causes a side effect
        answer = new PropertiesComponent(true);
        camelContext.addComponent("properties", answer);
    }
    return answer;
}
Also used : PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 72 with PropertiesComponent

use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.

the class FilerProducerDoneFileNameRouteTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            myProp.put("myDir", "target/done");
            PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
            pc.setLocation("ref:myProp");
            from("direct:start").to("file:{{myDir}}?doneFileName=done-${file:name}").to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 73 with PropertiesComponent

use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.

the class ManagedFromRestPlaceholderTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("dummy-test", new DummyRestConsumerFactory());
    CamelContext answer = new DefaultCamelContext(registry);
    PropertiesComponent pc = new PropertiesComponent();
    pc.setLocation("classpath:org/apache/camel/management/rest.properties");
    answer.addComponent("properties", pc);
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DummyRestConsumerFactory(org.apache.camel.component.rest.DummyRestConsumerFactory) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 74 with PropertiesComponent

use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.

the class PropertyInjectAnnotationParameterTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    PropertiesComponent pc = new PropertiesComponent();
    Properties props = new Properties();
    props.put("greeting", "Hello");
    props.put("times", "3");
    pc.setInitialProperties(props);
    context.addComponent("properties", pc);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) Properties(java.util.Properties) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 75 with PropertiesComponent

use of org.apache.camel.component.properties.PropertiesComponent in project camel by apache.

the class AdvisedRouteTest method configuration.

@Produces
@ApplicationScoped
@Named("properties")
private static PropertiesComponent configuration() {
    Properties properties = new Properties();
    properties.put("from", "inbound");
    properties.put("to", "direct:outbound");
    properties.put("header.message", "n/a");
    PropertiesComponent component = new PropertiesComponent();
    component.setInitialProperties(properties);
    return component;
}
Also used : Properties(java.util.Properties) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

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