Search in sources :

Example 1 with ExpressionEvaluationException

use of org.apache.camel.ExpressionEvaluationException in project camel by apache.

the class SpelExpression method evaluate.

public <T> T evaluate(Exchange exchange, Class<T> tClass) {
    try {
        Expression expression = parseExpression();
        EvaluationContext evaluationContext = createEvaluationContext(exchange);
        Object value = expression.getValue(evaluationContext);
        // Let Camel handle the type conversion
        return exchange.getContext().getTypeConverter().convertTo(tClass, value);
    } catch (Exception e) {
        throw new ExpressionEvaluationException(this, exchange, e);
    }
}
Also used : ExpressionEvaluationException(org.apache.camel.ExpressionEvaluationException) Expression(org.springframework.expression.Expression) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) EvaluationContext(org.springframework.expression.EvaluationContext) ExpressionEvaluationException(org.apache.camel.ExpressionEvaluationException)

Example 2 with ExpressionEvaluationException

use of org.apache.camel.ExpressionEvaluationException in project camel by apache.

the class OgnlExpression method evaluate.

public <T> T evaluate(Exchange exchange, Class<T> tClass) {
    OgnlContext oglContext = new OgnlContext();
    // setup the class resolver from camel
    oglContext.setClassResolver(new CamelClassResolver(exchange.getContext().getClassResolver()));
    try {
        Object value = Ognl.getValue(expression, oglContext, new RootObject(exchange));
        return exchange.getContext().getTypeConverter().convertTo(tClass, value);
    } catch (OgnlException e) {
        throw new ExpressionEvaluationException(this, exchange, e);
    }
}
Also used : OgnlException(ognl.OgnlException) ExpressionEvaluationException(org.apache.camel.ExpressionEvaluationException) OgnlContext(ognl.OgnlContext)

Example 3 with ExpressionEvaluationException

use of org.apache.camel.ExpressionEvaluationException in project camel by apache.

the class JXPathExpression method evaluate.

public <T> T evaluate(Exchange exchange, Class<T> tClass) {
    try {
        JXPathContext context = JXPathContext.newContext(exchange);
        context.setLenient(lenient);
        Object result = getJXPathExpression().getValue(context, type);
        assertResultType(exchange, result);
        return exchange.getContext().getTypeConverter().convertTo(tClass, result);
    } catch (JXPathException e) {
        throw new ExpressionEvaluationException(this, exchange, e);
    }
}
Also used : ExpressionEvaluationException(org.apache.camel.ExpressionEvaluationException) JXPathContext(org.apache.commons.jxpath.JXPathContext) JXPathException(org.apache.commons.jxpath.JXPathException)

Aggregations

ExpressionEvaluationException (org.apache.camel.ExpressionEvaluationException)3 OgnlContext (ognl.OgnlContext)1 OgnlException (ognl.OgnlException)1 JXPathContext (org.apache.commons.jxpath.JXPathContext)1 JXPathException (org.apache.commons.jxpath.JXPathException)1 EvaluationContext (org.springframework.expression.EvaluationContext)1 Expression (org.springframework.expression.Expression)1 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1