Java Code Examples for org.springframework.expression.ExpressionException

The following examples show how to use org.springframework.expression.ExpressionException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-technology-stack   Source File: SpelReproTests.java    License: MIT License 6 votes vote down vote up
private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) {
	SpelExpressionParser parser = new SpelExpressionParser();
	try {
		parser.parseExpression(expression, context);
		fail("Should have failed with message: " + expectedMessage);
	}
	catch (Exception ex) {
		String message = ex.getMessage();
		if (ex instanceof ExpressionException) {
			message = ((ExpressionException) ex).getSimpleMessage();
		}
		if (!message.equals(expectedMessage)) {
			ex.printStackTrace();
		}
		assertThat(expectedMessage, equalTo(message));
	}
}
 
Example 2
Source Project: spring4-understanding   Source File: SpelReproTests.java    License: Apache License 2.0 6 votes vote down vote up
private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) throws Exception {
	SpelExpressionParser parser = new SpelExpressionParser();
	try {
		parser.parseExpression(expression, context);
		fail("Should have failed with message: " + expectedMessage);
	}
	catch (Exception ex) {
		String message = ex.getMessage();
		if (ex instanceof ExpressionException) {
			message = ((ExpressionException) ex).getSimpleMessage();
		}
		if (!message.equals(expectedMessage)) {
			ex.printStackTrace();
		}
		assertThat(expectedMessage, equalTo(message));
	}
}
 
Example 3
Source Project: spring-analysis-note   Source File: SpelReproTests.java    License: MIT License 5 votes vote down vote up
private void checkTemplateParsingError(String expression, ParserContext context, String expectedMessage) {
	SpelExpressionParser parser = new SpelExpressionParser();
	try {
		parser.parseExpression(expression, context);
		fail("Should have failed with message: " + expectedMessage);
	}
	catch (Exception ex) {
		String message = ex.getMessage();
		if (ex instanceof ExpressionException) {
			message = ((ExpressionException) ex).getSimpleMessage();
		}
		if (!message.equals(expectedMessage)) {
			ex.printStackTrace();
		}
		assertThat(expectedMessage, equalTo(message));
	}
}
 
Example 4
Source Project: spring-sync   Source File: PatchOperation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves a value from the operation's path.
 * @param target the target object.
 * @return the value at the path on the given target object.
 */
protected Object getValueFromTarget(Object target) {
	try {
		return spelExpression.getValue(target);
	} catch (ExpressionException e) {
		throw new PatchException("Unable to get value from target", e);
	}
}
 
Example 5
public String interpolate(String messageTemplate, Map<String, Object> variables) {
    Assert.notNull(messageTemplate, "messageTemplate must not be null");

    try {
        Expression expression = parser().parseExpression(messageTemplate, new TemplateParserContext());

        return expression.getValue(evalContext, variables, String.class);

    } catch (ExpressionException ex) {
        LOG.error("Failed to interpolate message template: {}", messageTemplate, ex);
        return "";
    }
}