Search in sources :

Example 1 with BridgePropertyPlaceholderConfigurer

use of org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer 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)

Aggregations

ArrayList (java.util.ArrayList)1 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)1 PropertiesLocation (org.apache.camel.component.properties.PropertiesLocation)1 BridgePropertyPlaceholderConfigurer (org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer)1