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;
}
}