Search in sources :

Example 6 with PropertiesLocation

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

the class BlueprintPropertiesLocationElementOptionalTest method testPropertiesLocationElement.

@Test
public void testPropertiesLocationElement() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedHeaderReceived("property-1", "property-value-1");
    mock.expectedHeaderReceived("property-2", "property-value-2");
    mock.expectedHeaderReceived("cm", "cm-value");
    PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
    assertNotNull("Properties component not defined", pc);
    List<PropertiesLocation> locations = pc.getLocations();
    assertNotNull(locations);
    assertEquals("Properties locations", 3, locations.size());
    template.sendBody("direct:start", null);
    mock.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Test(org.junit.Test)

Example 7 with PropertiesLocation

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

the class BlueprintPropertiesLocationElementTest method testPropertiesLocationElement.

@Test
public void testPropertiesLocationElement() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedHeaderReceived("property-1", "property-value-1");
    mock.expectedHeaderReceived("property-2", "property-value-2");
    mock.expectedHeaderReceived("cm", "cm-value");
    PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
    assertNotNull("Properties component not defined", pc);
    List<PropertiesLocation> locations = pc.getLocations();
    assertNotNull(locations);
    assertEquals("Properties locations", 3, locations.size());
    template.sendBody("direct:start", null);
    mock.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) Test(org.junit.Test)

Example 8 with PropertiesLocation

use of org.apache.camel.component.properties.PropertiesLocation 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

PropertiesLocation (org.apache.camel.component.properties.PropertiesLocation)8 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)7 Test (org.junit.Test)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 PropertiesResolver (org.apache.camel.component.properties.PropertiesResolver)2 CamelContext (org.apache.camel.CamelContext)1 PropertiesFunction (org.apache.camel.component.properties.PropertiesFunction)1 PropertiesParser (org.apache.camel.component.properties.PropertiesParser)1 BridgePropertyPlaceholderConfigurer (org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer)1