Search in sources :

Example 1 with PropertiesComponent

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

the class InjectedTypeConverterTest method configuration.

@Produces
@ApplicationScoped
@Named("properties")
private static PropertiesComponent configuration() {
    Properties properties = new Properties();
    properties.put("property1", "value 1");
    properties.put("property2", "value 2");
    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)

Example 2 with PropertiesComponent

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

the class MultiContextPropertyInjectTest method configuration.

@Produces
@ApplicationScoped
@Named("properties")
private static PropertiesComponent configuration() {
    Properties properties = new Properties();
    properties.put("property", "default");
    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)

Example 3 with PropertiesComponent

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

the class PropertyInjectTest method configuration.

@Produces
@ApplicationScoped
@Named("properties")
private static PropertiesComponent configuration() {
    Properties properties = new Properties();
    properties.put("property", "value");
    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)

Example 4 with PropertiesComponent

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

the class UndefinedPropertyTest method configuration.

@Produces
@ApplicationScoped
@Named("properties")
private static PropertiesComponent configuration() {
    Properties properties = new Properties();
    properties.put("from", "inbound");
    // Do not add the looked up property for test purpose
    //properties.put("to", "mock:outbound");
    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)

Example 5 with PropertiesComponent

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

the class AbstractCamelContextFactoryBean method initPropertyPlaceholder.

protected void initPropertyPlaceholder() throws Exception {
    if (getCamelPropertyPlaceholder() != null) {
        CamelPropertyPlaceholderDefinition def = getCamelPropertyPlaceholder();
        List<PropertiesLocation> locations = new ArrayList<>();
        if (def.getLocation() != null) {
            ObjectHelper.createIterable(def.getLocation()).forEach(location -> locations.add(new PropertiesLocation((String) location)));
        }
        if (def.getLocations() != null) {
            def.getLocations().forEach(definition -> locations.add(definition.toLocation()));
        }
        PropertiesComponent pc = new PropertiesComponent();
        pc.setLocations(locations);
        pc.setEncoding(def.getEncoding());
        if (def.isCache() != null) {
            pc.setCache(def.isCache());
        }
        if (def.isIgnoreMissingLocation() != null) {
            pc.setIgnoreMissingLocation(def.isIgnoreMissingLocation());
        }
        // if using a custom resolver
        if (ObjectHelper.isNotEmpty(def.getPropertiesResolverRef())) {
            PropertiesResolver resolver = CamelContextHelper.mandatoryLookup(getContext(), def.getPropertiesResolverRef(), PropertiesResolver.class);
            pc.setPropertiesResolver(resolver);
        }
        // if using a custom parser
        if (ObjectHelper.isNotEmpty(def.getPropertiesParserRef())) {
            PropertiesParser parser = CamelContextHelper.mandatoryLookup(getContext(), def.getPropertiesParserRef(), PropertiesParser.class);
            pc.setPropertiesParser(parser);
        }
        pc.setPropertyPrefix(def.getPropertyPrefix());
        pc.setPropertySuffix(def.getPropertySuffix());
        if (def.isFallbackToUnaugmentedProperty() != null) {
            pc.setFallbackToUnaugmentedProperty(def.isFallbackToUnaugmentedProperty());
        }
        if (def.getDefaultFallbackEnabled() != null) {
            pc.setDefaultFallbackEnabled(def.getDefaultFallbackEnabled());
        }
        pc.setPrefixToken(def.getPrefixToken());
        pc.setSuffixToken(def.getSuffixToken());
        if (def.getFunctions() != null && !def.getFunctions().isEmpty()) {
            for (CamelPropertyPlaceholderFunctionDefinition function : def.getFunctions()) {
                String ref = function.getRef();
                PropertiesFunction pf = CamelContextHelper.mandatoryLookup(getContext(), ref, PropertiesFunction.class);
                pc.addFunction(pf);
            }
        }
        // register the properties component
        getContext().addComponent("properties", pc);
    }
}
Also used : PropertiesParser(org.apache.camel.component.properties.PropertiesParser) PropertiesResolver(org.apache.camel.component.properties.PropertiesResolver) ArrayList(java.util.ArrayList) PropertiesLocation(org.apache.camel.component.properties.PropertiesLocation) PropertiesFunction(org.apache.camel.component.properties.PropertiesFunction) 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