Package org.apache.camel.component.properties

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


        // no language resolved
        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

    protected void startCamel() throws Exception {
        camel = new DefaultCamelContext();

        // add properties component
        camel.addComponent("properties", new PropertiesComponent("classpath:incident.properties,file:target/custom.properties"));

        ReportIncidentRoutes routes = new ReportIncidentRoutes();
        routes.setUsingServletTransport(false);
        camel.addRoutes(routes);
        camel.start();
View Full Code Here

    protected void initPropertyPlaceholder() throws Exception {
        if (getCamelPropertyPlaceholder() != null) {
            CamelPropertyPlaceholderDefinition def = getCamelPropertyPlaceholder();

            PropertiesComponent pc = new PropertiesComponent();
            pc.setLocation(def.getLocation());

            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());
            }
           
            pc.setPrefixToken(def.getPrefixToken());
            pc.setSuffixToken(def.getSuffixToken());

            // register the properties component
            getContext().addComponent("properties", pc);
        }
    }
View Full Code Here

        props.put("somewhere", "mock:changed");
        props.put("theBar", "mock:bar");

        CamelContext context = super.createCamelContext();

        PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
        pc.setLocations(new String[0]);
        pc.setOverrideProperties(props);

        return context;
    }
View Full Code Here

                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

    protected void initPropertyPlaceholder() throws Exception {
        if (getCamelPropertyPlaceholder() != null) {
            CamelPropertyPlaceholderDefinition def = getCamelPropertyPlaceholder();

            PropertiesComponent pc = new PropertiesComponent();
            pc.setLocation(def.getLocation());

            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());
            }
           
            pc.setPrefixToken(def.getPrefixToken());
            pc.setSuffixToken(def.getSuffixToken());

            // register the properties component
            getContext().addComponent("properties", pc);
        }
    }
View Full Code Here

            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 = getContext().getComponent("properties", PropertiesComponent.class);
            // replace existing resolver with us
            configurer.setResolver(pc.getPropertiesResolver());
            configurer.setParser(pc.getPropertiesParser());
            String ref = "ref:" + id;
            // use the bridge to handle the resolve and parsing
            pc.setPropertiesResolver(configurer);
            pc.setPropertiesParser(configurer);
            // and update locations to have our as ref first
            String[] locations = pc.getLocations();
            String[] updatedLocations;
            if (locations != null && locations.length > 0) {
                updatedLocations = new String[locations.length + 1];
                updatedLocations[0] = ref;
                System.arraycopy(locations, 0, updatedLocations, 1, locations.length);
            } else {
                updatedLocations = new String[]{ref};
            }
            pc.setLocations(updatedLocations);
        } 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());
        }
    }
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.