@Override public Object getValue(String paramName) throws IllegalArgumentException { Object answer; if ("body".equals(paramName)) { answer = exchange.getIn().getBody(); } else if ((paramName.startsWith("$simple{") || paramName.startsWith("${")) && paramName.endsWith("}")) { // its a simple language expression // spring org.springframework.jdbc.core.namedparam.NamedParameterUtils.PARAMETER_SEPARATORS // uses : as parameter separator and we may use colon in simple languages as well such as bean:foo // so we have to use # instead and replace them back paramName = paramName.replace('#', ':'); answer = SimpleLanguage.expression(paramName).evaluate(exchange, Object.class); } else { answer = bodyMap.get(paramName); if (answer == null) { answer = headersMap.get(paramName); } } return answer; } }
protected GenericFileEndpoint<File> buildFileEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { // the starting directory must be a static (not containing dynamic expressions) if (SimpleLanguage.hasStartToken(remaining)) { throw new IllegalArgumentException("Invalid directory: " + remaining + ". Dynamic expressions with ${ } placeholders is not allowed." + " Use the fileName option to set the dynamic expression."); } getFiles(remaining); File file = new File(TEMP_FOLDER); FileEndpoint result = new FileEndpoint(uri, this); result.setFile(file); GenericFileConfiguration config = new GenericFileConfiguration(); config.setDirectory(file.getPath()); result.setConfiguration(config); return result; }
@ConditionalOnMissingBean(FileLanguage.class) public FileLanguage configureFileLanguage() throws Exception { FileLanguage language = new FileLanguage(); if (CamelContextAware.class.isAssignableFrom(FileLanguage.class)) { CamelContextAware contextAware = CamelContextAware.class
@ConditionalOnMissingBean(SimpleLanguage.class) public SimpleLanguage configureSimpleLanguage() throws Exception { SimpleLanguage language = new SimpleLanguage(); if (CamelContextAware.class.isAssignableFrom(SimpleLanguage.class)) { CamelContextAware contextAware = CamelContextAware.class
protected <C> C simple(Exchange exchange, String expression, Class<C> clazz) { if (expression != null) { Expression simple = SimpleLanguage.simple(expression); if (simple != null) { return simple.evaluate(exchange, clazz); } } return getEndpoint().getCamelContext().getTypeConverter().convertTo(clazz, expression); }
@SuppressWarnings("unchecked") private void configureParameters(Query query, Exchange exchange) { int maxResults = getEndpoint().getMaximumResults(); if (maxResults > 0) { query.setMaxResults(maxResults); } // setup the parameters Map<String, ?> params; if (parameters != null) { params = parameters; } else { params = exchange.getIn().getHeader(JpaConstants.JPA_PARAMETERS_HEADER, Map.class); } if (params != null) { params.forEach((key, value) -> { Object resolvedValue = value; if (value instanceof String) { resolvedValue = SimpleLanguage.expression((String)value).evaluate(exchange, Object.class); } query.setParameter(key, resolvedValue); }); } }
protected static Object lookupParameter(String nextParam, Exchange exchange, Object body) { Map<?, ?> bodyMap = safeMap(exchange.getContext().getTypeConverter().tryConvertTo(Map.class, body)); Map<?, ?> headersMap = safeMap(exchange.getIn().getHeaders()); Object answer = null; if ((nextParam.startsWith("$simple{") || nextParam.startsWith("${")) && nextParam.endsWith("}")) { answer = SimpleLanguage.expression(nextParam).evaluate(exchange, Object.class); } else if (bodyMap.containsKey(nextParam)) { answer = bodyMap.get(nextParam); } else if (headersMap.containsKey(nextParam)) { answer = headersMap.get(nextParam); } return answer; }