Package org.apache.camel.component.properties

Examples of org.apache.camel.component.properties.PropertiesComponent$CacheKey


                try {
                    if (locations != null) {
                        // the properties component is optional as we got locations
                        // getComponent will create a new component if none already exists
                        Component component = exchange.getContext().getComponent("properties");
                        PropertiesComponent pc = exchange.getContext().getTypeConverter()
                                .mandatoryConvertTo(PropertiesComponent.class, component);
                        // enclose key with {{ }} to force parsing
                        String[] paths = locations.split(",");
                        return pc.parseUri(pc.getPrefixToken() + key + pc.getSuffixToken(), paths);
                    } else {
                        // the properties component is mandatory if no locations provided
                        Component component = exchange.getContext().hasComponent("properties");
                        if (component == null) {
                            throw new IllegalArgumentException("PropertiesComponent with name properties must be defined"
                                    + " in CamelContext to support property placeholders in expressions");
                        }
                        PropertiesComponent pc = exchange.getContext().getTypeConverter()
                                .mandatoryConvertTo(PropertiesComponent.class, component);
                        // enclose key with {{ }} to force parsing
                        return pc.parseUri(pc.getPrefixToken() + key + pc.getSuffixToken());
                    }
                } catch (Exception e) {
                    throw ObjectHelper.wrapRuntimeCamelException(e);
                }
            }
View Full Code Here


        return answer;
    }
   
    public String getPropertyPrefixToken() {
        PropertiesComponent pc = getPropertiesComponent();
       
        if (pc != null) {
            return pc.getPrefixToken();
        } else {
            return null;
        }
    }
View Full Code Here

            return null;
        }
    }
   
    public String getPropertySuffixToken() {
        PropertiesComponent pc = getPropertiesComponent();
       
        if (pc != null) {
            return pc.getSuffixToken();
        } else {
            return null;
        }
    }
View Full Code Here

    public String resolvePropertyPlaceholders(String text) throws Exception {
        // While it is more efficient to only do the lookup if we are sure we need the component,
        // with custom tokens, we cannot know if the URI contains a property or not without having
        // the component.  We also lose fail-fast behavior for the missing component with this change.
        PropertiesComponent pc = getPropertiesComponent();

        // Do not parse uris that are designated for the properties component as it will handle that itself
        if (text != null && !text.startsWith("properties:")) {
            // No component, assume default tokens.
            if (pc == null && text.contains(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) {

                // try to lookup component, as we may be initializing CamelContext itself
                Component existing = lookupPropertiesComponent();
                if (existing != null) {
                    if (existing instanceof PropertiesComponent) {
                        pc = (PropertiesComponent) existing;
                    } else {
                        // properties component must be expected type
                        throw new IllegalArgumentException("Found properties component of type: " + existing.getClass() + " instead of expected: " + PropertiesComponent.class);
                    }
                }

                if (pc != null) {
                    // the parser will throw exception if property key was not found
                    String answer = pc.parseUri(text);
                    log.debug("Resolved text: {} -> {}", text, answer);
                    return answer;
                } else {
                    throw new IllegalArgumentException("PropertiesComponent with name properties must be defined"
                            + " in CamelContext to support property placeholders.");
                }
               
            // Component available, use actual tokens
            } else if (pc != null && text.contains(pc.getPrefixToken())) {
                // the parser will throw exception if property key was not found
                String answer = pc.parseUri(text);
                log.debug("Resolved text: {} -> {}", text, answer);
                return answer;
            }
        }
View Full Code Here

        }
    }

    protected Component lookupPropertiesComponent() {
        // no existing properties component so lookup and add as component if possible
        PropertiesComponent answer = (PropertiesComponent) hasComponent("properties");
        if (answer == null) {
            answer = getRegistry().lookupByNameAndType("properties", PropertiesComponent.class);
            if (answer != null) {
                addComponent("properties", answer);
            }
View Full Code Here

*/
public class Starter {

    public void run() throws Exception {
        CamelContext context = new DefaultCamelContext();
        context.addComponent("properties", new PropertiesComponent("sampleconfig.properties"));
        context.addRoutes(new OrderRouteBuilder());
        context.start();
        System.in.read();
        context.stop();
    }
View Full Code Here

    }

    @Override
    protected RouteBuilder[] createRouteBuilders() throws Exception {
        context.setTracing(true);
        PropertiesComponent properties = new PropertiesComponent("person2jms.cfg");
        context.addComponent("properties", properties);
        addTestJmsComponent();
       
        return new RouteBuilder[]{new Jms2RestRoute(), new RouteBuilder() {
           
View Full Code Here

        }
    }

    public static void setupPropertiesComponent(final CamelContext context, final Map<String, String> props, Logger log) {
        // Set up PropertiesComponent
        PropertiesComponent pc = new PropertiesComponent();
        if (context.getComponentNames().contains("properties")) {
            pc = context.getComponent("properties", PropertiesComponent.class);
        } else {
            context.addComponent("properties", pc);
        }

        // Set property prefix
        if (null != System.getProperty(PROPERTY_PREFIX)) {
            pc.setPropertyPrefix(System.getProperty(PROPERTY_PREFIX) + ".");
        }

        if (null != props) {
            Properties initialProps = new Properties();
            initialProps.putAll(props);
            log.debug(String.format("Added %d initial properties", props.size()));
            try {
                pc.setInitialProperties(initialProps);
            } catch (NoSuchMethodError e) {
                // For Camel versions without setInitialProperties
                pc.setOverrideProperties(initialProps);
                pc.setLocation("default.properties");
            }
        }
    }
View Full Code Here

        return new SpringPropertiesParser();
    }

    @Bean
    PropertiesComponent properties() {
        PropertiesComponent properties = new PropertiesComponent();
        properties.setPropertiesParser(propertiesParser());
        return properties;
    }
View Full Code Here

    @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;
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.properties.PropertiesComponent$CacheKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.