Search in sources :

Example 66 with PropertiesComponent

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

the class AbstractMongoDbTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    applicationContext = new AnnotationConfigApplicationContext(EmbedMongoConfiguration.class);
    CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
    ctx.addComponent("properties", pc);
    return ctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 67 with PropertiesComponent

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

the class AbstractMongoDbTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    applicationContext = new AnnotationConfigApplicationContext(EmbedMongoConfiguration.class);
    CamelContext ctx = SpringCamelContext.springCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
    ctx.addComponent("properties", pc);
    return ctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 68 with PropertiesComponent

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

the class AbstractMongoDbTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    applicationContext = new AnnotationConfigApplicationContext(EmbedMongoConfiguration.class);
    @SuppressWarnings("deprecation") CamelContext ctx = SpringCamelContext.springCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:mongodb.test.properties");
    ctx.addComponent("properties", pc);
    return ctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 69 with PropertiesComponent

use of org.apache.camel.component.properties.PropertiesComponent 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());
    }
}
Also used : ArrayList(java.util.ArrayList) PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) BridgePropertyPlaceholderConfigurer(org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer)

Example 70 with PropertiesComponent

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

the class Main method setPropertyPlaceholderLocations.

/**
     * A list of locations to load properties. You can use comma to separate multiple locations.
     * This option will override any default locations and only use the locations from this option.
     */
protected void setPropertyPlaceholderLocations(String location) {
    PropertiesComponent pc = new PropertiesComponent();
    pc.setLocation(location);
    bind("properties", pc);
}
Also used : 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