Example usage for org.springframework.expression EvaluationException getCause

List of usage examples for org.springframework.expression EvaluationException getCause

Introduction

In this page you can find the example usage for org.springframework.expression EvaluationException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.springframework.integration.util.AbstractExpressionEvaluator.java

protected <T> T evaluateExpression(Expression expression, Message<?> message, Class<T> expectedType) {
    try {/*from  w  w  w  .j  ava2  s. co  m*/
        return evaluateExpression(expression, (Object) message, expectedType);
    } catch (EvaluationException e) {
        Throwable cause = e.getCause();
        if (this.logger.isDebugEnabled()) {
            logger.debug("SpEL Expression evaluation failed with EvaluationException.", e);
        }
        throw new MessageHandlingException(message,
                "Expression evaluation failed: " + expression.getExpressionString(), cause == null ? e : cause);
    } catch (Exception e) {
        if (this.logger.isDebugEnabled()) {
            logger.debug("SpEL Expression evaluation failed with Exception." + e);
        }
        throw new MessageHandlingException(message,
                "Expression evaluation failed: " + expression.getExpressionString(), e);
    }
}

From source file:org.springframework.integration.util.MessagingMethodInvokerHelper.java

private T processInternal(ParametersWrapper parameters) throws Exception {
    Throwable evaluationException = null;
    List<HandlerMethod> candidates = this.findHandlerMethodsForParameters(parameters);
    Assert.state(!candidates.isEmpty(), "No candidate methods found for messages.");
    for (HandlerMethod candidate : candidates) {
        try {//  ww  w .j  a  va2s  . co m
            Expression expression = candidate.getExpression();
            Class<?> expectedType = this.expectedType != null ? this.expectedType
                    : candidate.method.getReturnType();
            @SuppressWarnings("unchecked")
            T result = (T) this.evaluateExpression(expression, parameters, expectedType);
            if (this.requiresReply) {
                Assert.notNull(result,
                        "Expression evaluation result was null, but this processor requires a reply.");
            }
            return result;
        }
        // keep the first exception
        catch (EvaluationException e) {
            if (evaluationException == null) {
                evaluationException = e.getCause();
            }
            if (evaluationException == null) {
                evaluationException = e;
            }
        } catch (MessageHandlingException e) {
            if (evaluationException == null) {
                evaluationException = e.getCause();
            }
            if (evaluationException == null) {
                evaluationException = e;
            }
        } catch (Exception e) {
            if (evaluationException == null) {
                evaluationException = e;
            }
        }
    }
    if (evaluationException instanceof Exception) {
        throw (Exception) evaluationException;
    } else if (evaluationException instanceof Error) {
        throw (Error) evaluationException;
    } else {
        throw new IllegalStateException("Cannot process message", evaluationException);
    }
}