public static URI[] resolveURIs(CamelContext camelContext, String uriList) throws Exception { String[] uris; if (uriList != null) { uris = uriList.split(","); } else { uris = EtcdConstants.ETCD_DEFAULT_URIS.split(","); } URI[] etcdUriList = new URI[uris.length]; for (int i = 0; i < uris.length; i++) { etcdUriList[i] = camelContext != null ? URI.create(camelContext.resolvePropertyPlaceholders(uris[i])) : URI.create(uris[i]); } return etcdUriList; } }
public static InputStream openInputStream(CamelContext camelContext, String uri) throws Exception { if (camelContext != null) { uri = camelContext.resolvePropertyPlaceholders(uri); return ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri); } return Thread.currentThread().getContextClassLoader().getResourceAsStream(uri); } }
/** * Tokenize a property placeholder value * * @param context the camel context * @param property the name of the property placeholder * @param token the token used for splitting the value * @return a list of values */ public static List<String> tokenizePropertyPlaceholder(final CamelContext context, final String property, final String token) { try { return stream(context.resolvePropertyPlaceholders(property).split(token)).map(String::trim) .filter(val -> !val.isEmpty()).collect(toList()); } catch (final Exception ex) { LOGGER.debug("No property value found for {}", property); return emptyList(); } } }
public static void setProperties(final CamelContext context, final Object target, final Map<String, Object> properties) { final Iterator<Map.Entry<String, Object>> iterator = properties.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, Object> entry = iterator.next(); final String key = entry.getKey(); Object val = entry.getValue(); try { if (val instanceof String) { val = context.resolvePropertyPlaceholders((String) val); } // Bind properties to the customizer if (IntrospectionSupport.setProperty(context, target, key, val)) { // Remove property if bound to the customizer. iterator.remove(); } } catch (final Exception e) { throw new IllegalStateException("Unable to set property `" + key + "` = `" + val + "`", e); } } }
public static <T> T configure(final CamelContext context, final T target, final Logger log, final boolean deep) { Class<?> clazz = target.getClass(); log.debug("Configuring {}", clazz.getName()); Collection<Field> fields = new ArrayList<>(); fields.addAll(Arrays.asList(clazz.getDeclaredFields())); if (deep) { fields.addAll(Arrays.asList(clazz.getFields())); fields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); } for (Field field : fields) { String propertyValue; try { propertyValue = context.resolvePropertyPlaceholders("{{" + field.getName() + "}}"); } catch (Exception e) { log.debug("Skipped field {}", field.getName()); continue; } try { if (!propertyValue.isEmpty()) { // Try to convert the value and set the field Object convertedValue = convertValue(propertyValue, field.getGenericType()); ReflectionHelper.setField(field, target, convertedValue); log.debug("Configured field {} with value {}", field.getName(), propertyValue); } } catch (Exception e) { log.warn("Error setting field " + field.getName() + " due: " + e.getMessage() + ". This exception is ignored.", e); } } return target; }
/** * Define how the message should be processed. * * @param exchange the current camel message exchange */ public void process(final Exchange exchange) throws IOException { final Message in = exchange.getIn(); final CamelContext ctx = exchange.getContext(); final StringBuilder key = new StringBuilder("/buckets/"); try { final String prefix = ctx.resolvePropertyPlaceholders("{{riak.bucket}}"); key.append(prefix); } catch (final Exception ex) { throw new RuntimeCamelException("Could not resolve properties", ex); } key.append("/keys/"); key.append(URLEncoder.encode( in.getHeader(FcrepoHeaders.FCREPO_IDENTIFIER, String.class), "UTF-8")); in.removeHeader(Exchange.HTTP_URL); in.setHeader(Exchange.HTTP_PATH, key.toString()); } }
@Override public List<ServiceDefinition> getServices(String name) { try { final CamelContext ctx = getCamelContext(); final String host = ctx.resolvePropertyPlaceholders("{{service.host:" + name + "}}"); final String num = ctx.resolvePropertyPlaceholders("{{service.port:" + name + "}}"); final int port = ctx.getTypeConverter().tryConvertTo(int.class, num); return Collections.singletonList(new DefaultServiceDefinition(name, host, port)); } catch (IllegalArgumentException e) { return Collections.emptyList(); } catch (Exception e) { throw new RuntimeCamelException(e); } }
val = getCamelContext().resolvePropertyPlaceholders((String) val);
protected String resolvePropertyPlaceholders(String str) { try { if (getCamelContext() != null) { return getCamelContext().resolvePropertyPlaceholders(str); } else { return str; } } catch (Exception ex) { throw ObjectHelper.wrapRuntimeCamelException(ex); } }
uri = exchange.getContext().resolvePropertyPlaceholders(uri); } catch (Exception e) { throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString); } catch (Exception e) { throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
protected String resolvePropertyPlaceholders(String str) { try { if (getCamelContext() != null) { return getCamelContext().resolvePropertyPlaceholders(str); } else { return str; } } catch (Exception ex) { throw ObjectHelper.wrapRuntimeCamelException(ex); } }
uri = exchange.getContext().resolvePropertyPlaceholders(uri); } catch (Exception e) { throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString); } catch (Exception e) { throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
val = getCamelContext().resolvePropertyPlaceholders((String) val);
protected Cache<K, V> doGetCache(JCacheProvider jcacheProvider) throws Exception { if (cache == null) { String uri = configuration.getConfigurationUri(); if (uri != null && camelContext != null) { uri = camelContext.resolvePropertyPlaceholders(uri); } provider = ObjectHelper.isNotEmpty(jcacheProvider.className()) ? Caching.getCachingProvider(jcacheProvider.className()) : Caching.getCachingProvider(); manager = provider.getCacheManager( ObjectHelper.isNotEmpty(uri) ? URI.create(uri) : null, null, configuration.getCacheConfigurationProperties()); cache = manager.getCache(cacheName); if (cache == null) { if (!configuration.isCreateCacheIfNotExists()) { throw new IllegalStateException( "Cache " + cacheName + " does not exist and should not be created (createCacheIfNotExists=false)"); } cache = manager.createCache( cacheName, getOrCreateCacheConfiguration()); } } return cache; }
uri = camelContext.resolvePropertyPlaceholders(uri); try (InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri)) { Properties properties = new Properties();
String configUri = getAndRemoveParameter(parameters, HAZELCAST_CONFIGU_URI_PARAM, String.class); if (configUri != null) { configUri = getCamelContext().resolvePropertyPlaceholders(configUri);
component.setConnectionCount(Integer.valueOf(context.resolvePropertyPlaceholders("{{jms.maxConnections}}"))); context.addComponent("sjms", component);
uri = camelContext.resolvePropertyPlaceholders(uri); try (InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri)) { Properties properties = new Properties();