@Override public Object convert( Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) { try { if (currentExchange.get() == null) { throw new IllegalStateException("Current exchange has not been set for ExpressionMapper"); } Expression exp; // Resolve the language being used for this expression and evaluate Exchange exchange = currentExchange.get(); Language expLang = exchange.getContext().resolveLanguage(getLanguagePart()); String scheme = getSchemePart(); if (scheme != null && (scheme.equalsIgnoreCase("classpath") || scheme.equalsIgnoreCase("file") || scheme.equalsIgnoreCase("http"))) { String path = getPathPart(); try { exp = expLang.createExpression(resolveScript(scheme + ":" + path)); } catch (IOException e) { throw new IllegalStateException("Expression script specified but not found", e); } } else { exp = expLang.createExpression(getExpressionPart()); } return exp.evaluate(exchange, destinationClass); } finally { done(); } }
private Expression createFileLanguageExpression(String expression) { Language language; // only use file language if the name is complex (eg. using $) if (expression.contains("$")) { language = getCamelContext().resolveLanguage("file"); } else { language = getCamelContext().resolveLanguage("constant"); } return language.createExpression(expression); }
/** * Asserts that the given language name and predicate expression evaluates to the expected value * on the message exchange */ protected void assertPredicate( String languageName, String expressionText, Exchange exchange, boolean expected) { Language language = assertResolveLanguage(languageName); Predicate predicate = language.createPredicate(expressionText); assertNotNull( "No Predicate could be created for text: " + expressionText + " language: " + language, predicate); assertPredicate(predicate, exchange, expected); }
/** * Asserts that the given language name and expression evaluates to the given value on a specific * exchange */ protected void assertExpression( Exchange exchange, String languageName, String expressionText, Object expectedValue) { Language language = assertResolveLanguage(languageName); Expression expression = language.createExpression(expressionText); assertNotNull( "No Expression could be created for text: " + expressionText + " language: " + language, expression); assertExpression(expression, exchange, expectedValue); }
public Predicate getRetryWhilePolicy(CamelContext context) { Predicate answer = getRetryWhile(); if (getRetryWhileRef() != null) { // its a bean expression Language bean = context.resolveLanguage("bean"); answer = bean.createPredicate(getRetryWhileRef()); } return answer; }