Example usage for org.springframework.expression.spel SpelEvaluationException getMessage

List of usage examples for org.springframework.expression.spel SpelEvaluationException getMessage

Introduction

In this page you can find the example usage for org.springframework.expression.spel SpelEvaluationException getMessage.

Prototype

@Override
public String getMessage() 

Source Link

Document

Return the exception message.

Usage

From source file:org.springjutsu.validation.spel.SPELResolver.java

/**
 * Evaluates a SPEL expression within the
 * current web context, returning the result.
 * @param spel String SPEL expression/*from   w  w  w .ja v a  2 s .  co  m*/
 * @return result of evaluated SPEL expression.
 */
public Object getBySpel(String spel) {
    try {
        return expressionParser.parseExpression(spel).getValue(scopedContext);
        // TODO: pretty sure we can get around this expensive catch with an always-null property accessor.
    } catch (SpelEvaluationException see) {
        if (see.getMessage().contains("cannot be found")) {
            return null;
        } else {
            throw see;
        }
    }
}

From source file:com.creactiviti.piper.core.task.SpelTaskEvaluator.java

private Object evaluate(Object aValue, Context aContext) {
    StandardEvaluationContext context = createEvaluationContext(aContext);
    if (aValue instanceof String) {
        Expression expression = parser.parseExpression((String) aValue,
                new TemplateParserContext(PREFIX, SUFFIX));
        try {/*  ww  w .ja  v a  2  s  .  c o  m*/
            return (expression.getValue(context));
        } catch (SpelEvaluationException e) {
            logger.debug(e.getMessage());
            return aValue;
        }
    } else if (aValue instanceof List) {
        List<Object> evaluatedlist = new ArrayList<>();
        List<Object> list = (List<Object>) aValue;
        for (Object item : list) {
            evaluatedlist.add(evaluate(item, aContext));
        }
        return evaluatedlist;
    } else if (aValue instanceof Map) {
        return evaluateInternal((Map<String, Object>) aValue, aContext);
    }
    return aValue;
}

From source file:com.enonic.cms.core.portal.datasource.el.ExpressionFunctionsExecutor.java

public String evaluate(final String expression) {
    final ExpressionRootObject rootObject = new ExpressionRootObject();

    rootObject.setSession(new SessionAccessor(verticalSession));
    rootObject.setCookie(new CookieAccessor(httpRequest));
    rootObject.setProperties(new CmsAndSitePropertiesAccessor(rootProperties, siteProperties));
    rootObject.setPortal(new PortalAccessor(expressionContext));
    rootObject.setUser(new UserAccessor(expressionContext.getUser()));
    rootObject.setParam(new ParamAccessor(requestParameters));
    rootObject.setParams(new ParamsAccessor(requestParameters));

    final String evaluatedString;

    try {//from w  w w  .j a va2s  . c o  m
        final StandardEvaluationContext context = new StandardEvaluationContext(rootObject);

        context.setPropertyAccessors(PROPERTY_ACCESSORS);

        ExpressionFunctionsFactory.get().setContext(expressionContext);

        Object result;

        try {
            final Expression exp = EXPR_FACTORY.parseExpression(expression, TEMPLATE_PARSER_CONTEXT);

            result = exp.getValue(context);
        } catch (SpelEvaluationException e) {
            result = null;
        } catch (Exception e) {
            LOG.error(e.getMessage());

            result = "ERROR: " + e.getMessage();
        }

        // must be converted here, because param.x[0] will not work
        if (result instanceof String[]) {
            evaluatedString = StringUtils.join((String[]) result, ',');
        } else {
            evaluatedString = result != null ? result.toString() : null;
        }
    } finally {
        ExpressionFunctionsFactory.get().removeContext();
    }

    return evaluatedString;
}

From source file:bugs.TestEL.java

/**
 * Test the EL.//  www. ja  v a 2 s . c o m
 */
@SuppressWarnings({ "boxing", "deprecation" })
@Test
public void testName() {
    // Arrange
    final SpelExpressionParser parser = new SpelExpressionParser();
    final StandardEvaluationContext context = new StandardEvaluationContext();

    final String spelExpression1 = "testDate.date";
    final String spelExpression2 = "class";
    final String spelExpression3 = "class.name";
    final String spelExpression4 = "name";

    final Date now = new Date();
    final String name = "Testname";

    final TestObject testObject = new TestObject();
    testObject.setTestDate(now);
    testObject.setName(name);

    final SpelExpression exp1 = (SpelExpression) parser.parseExpression(spelExpression1);
    final SpelExpression exp2 = (SpelExpression) parser.parseExpression(spelExpression2);
    final SpelExpression exp3 = (SpelExpression) parser.parseExpression(spelExpression3);
    final SpelExpression exp4 = (SpelExpression) parser.parseExpression(spelExpression4);
    // Act

    final Object value1 = exp1.getValue(context, testObject);

    final Object value2 = exp2.getValue(context, testObject);

    final Object value3 = exp3.getValue(context, testObject);

    Object value4 = null;
    try {
        value4 = exp4.getValue(context, testObject);
    } catch (SpelEvaluationException e) {
        Assert.assertEquals(
                "EL1021E:(pos 0): A problem occurred whilst " + "attempting to access the property 'name': "
                        + "'Unable to access property 'name' through getter'",
                e.getMessage());
        // CSOFF: RegexpSinglelineJava
        System.err.println("Spring-Bug SPR-9017 happens!");
        // CSON: RegexpSinglelineJava
        value4 = name;
    }

    // Assert
    Assert.assertEquals(value1, now.getDate());
    Assert.assertEquals(value2, TestObject.class);
    Assert.assertEquals(value3, TestObject.class.getName());
    Assert.assertEquals(value4, name);

}

From source file:com.vedri.mtp.frontend.support.stomp.DefaultSubscriptionRegistry.java

private MultiValueMap<String, String> filterSubscriptions(MultiValueMap<String, String> allMatches,
        Message<?> message) {//from  w  w  w  .  j ava2s. c  o  m

    if (!this.selectorHeaderInUse) {
        return allMatches;
    }
    EvaluationContext context = null;
    MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(allMatches.size());
    for (String sessionId : allMatches.keySet()) {
        for (String subId : allMatches.get(sessionId)) {
            SessionSubscriptionInfo info = this.subscriptionRegistry.getSubscriptions(sessionId);
            if (info == null) {
                continue;
            }
            Subscription sub = info.getSubscription(subId);
            if (sub == null) {
                continue;
            }
            Expression expression = sub.getSelectorExpression();
            if (expression == null) {
                result.add(sessionId, subId);
                continue;
            }
            if (context == null) {
                context = new StandardEvaluationContext(message);
                context.getPropertyAccessors().add(new SimpMessageHeaderPropertyAccessor());
            }
            try {
                if (expression.getValue(context, boolean.class)) {
                    result.add(sessionId, subId);
                }
            } catch (SpelEvaluationException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Failed to evaluate selector: " + ex.getMessage());
                }
            } catch (Throwable ex) {
                logger.debug("Failed to evaluate selector", ex);
            }
        }
    }
    return result;
}