@Override public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression"); }
@Test public void indexIntoGenericPropertyContainingGrowingList() { List<String> property = new ArrayList<>(); this.property = property; SpelParserConfiguration configuration = new SpelParserConfiguration(true, true); SpelExpressionParser parser = new SpelExpressionParser(configuration); Expression expression = parser.parseExpression("property"); assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString()); assertEquals(property, expression.getValue(this)); expression = parser.parseExpression("property[0]"); try { assertEquals("bar", expression.getValue(this)); } catch (EvaluationException ex) { assertTrue(ex.getMessage().startsWith("EL1053E")); } }
@Test public void testScenario01_Roles() throws Exception { try { SpelExpressionParser parser = new SpelExpressionParser(); StandardEvaluationContext ctx = new StandardEvaluationContext(); Expression expr = parser.parseRaw("hasAnyRole('MANAGER','TELLER')"); ctx.setRootObject(new Person("Ben")); Boolean value = expr.getValue(ctx,Boolean.class); assertFalse(value); ctx.setRootObject(new Manager("Luke")); value = expr.getValue(ctx,Boolean.class); assertTrue(value); } catch (EvaluationException ee) { ee.printStackTrace(); fail("Unexpected SpelException: " + ee.getMessage()); } }
protected <T> T evaluateExpression(Expression expression, Message<?> message, Class<T> expectedType) { try { return evaluateExpression(expression, (Object) message, expectedType); } catch (EvaluationException e) { Throwable cause = e.getCause(); if (this.logger.isDebugEnabled()) { this.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()) { this.logger.debug("SpEL Expression evaluation failed with Exception." + e); } throw new MessageHandlingException(message, "Expression evaluation failed: " + expression.getExpressionString(), e); } }
@Test public void testSetValue() { try { LiteralExpression lEx = new LiteralExpression("somevalue"); lEx.setValue(new StandardEvaluationContext(), "flibble"); fail("Should have got an exception that the value cannot be set"); } catch (EvaluationException ee) { // success, not allowed - whilst here, check the expression value in the exception assertEquals("somevalue", ee.getExpressionString()); } try { LiteralExpression lEx = new LiteralExpression("somevalue"); lEx.setValue(new Rooty(), "flibble"); fail("Should have got an exception that the value cannot be set"); } catch (EvaluationException ee) { // success, not allowed - whilst here, check the expression value in the exception assertEquals("somevalue", ee.getExpressionString()); } try { LiteralExpression lEx = new LiteralExpression("somevalue"); lEx.setValue(new StandardEvaluationContext(), new Rooty(), "flibble"); fail("Should have got an exception that the value cannot be set"); } catch (EvaluationException ee) { // success, not allowed - whilst here, check the expression value in the exception assertEquals("somevalue", ee.getExpressionString()); } }
@Test public void indexIntoGenericPropertyContainingGrowingList2() { List<String> property2 = new ArrayList<>(); this.property2 = property2; SpelParserConfiguration configuration = new SpelParserConfiguration(true, true); SpelExpressionParser parser = new SpelExpressionParser(configuration); Expression expression = parser.parseExpression("property2"); assertEquals("java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString()); assertEquals(property2, expression.getValue(this)); expression = parser.parseExpression("property2[0]"); try { assertEquals("bar", expression.getValue(this)); } catch (EvaluationException ex) { assertTrue(ex.getMessage().startsWith("EL1053E")); } }
protected <T> T evaluateExpression(Expression expression, Message<?> message, Class<T> expectedType) { try { return evaluateExpression(expression, (Object) message, expectedType); } catch (EvaluationException e) { Throwable cause = e.getCause(); if (this.logger.isDebugEnabled()) { this.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()) { this.logger.debug("SpEL Expression evaluation failed with Exception." + e); } throw new MessageHandlingException(message, "Expression evaluation failed: " + expression.getExpressionString(), e); } }
@Override public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression"); }
@Test public void indexIntoGenericPropertyContainingNullList() { SpelParserConfiguration configuration = new SpelParserConfiguration(true, true); SpelExpressionParser parser = new SpelExpressionParser(configuration); Expression expression = parser.parseExpression("property"); assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.lang.Object", expression.getValueTypeDescriptor(this).toString()); assertEquals(property, expression.getValue(this)); expression = parser.parseExpression("property[0]"); try { assertEquals("bar", expression.getValue(this)); } catch (EvaluationException ex) { assertTrue(ex.getMessage().startsWith("EL1027E")); } }
@Override public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression"); }
@Test public void setGenericPropertyContainingListAutogrow() { List<Integer> property = new ArrayList<>(); this.property = property; SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression expression = parser.parseExpression("property"); assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.ArrayList<?>", expression.getValueTypeDescriptor(this).toString()); assertEquals(property, expression.getValue(this)); expression = parser.parseExpression("property[0]"); try { expression.setValue(this, "4"); } catch (EvaluationException ex) { assertTrue(ex.getMessage().startsWith("EL1053E")); } }
@Override public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression"); }
protected reactor.event.selector.Selector fetchSelector(Selector selectorAnno, Object bean, Method method) { Object sel = parseSelector(selectorAnno, bean, method); try { switch(selectorAnno.type()) { case OBJECT: return object(sel); case REGEX: return regex(sel.toString()); case URI: return uri(sel.toString()); case TYPE: try { return type(Class.forName(sel.toString())); } catch(ClassNotFoundException e) { throw new IllegalArgumentException(e.getMessage(), e); } case JSON_PATH: return jsonPathSelector(sel.toString()); } } catch(EvaluationException e) { if(LOG.isTraceEnabled()) { LOG.trace("Creating ObjectSelector for '" + sel + "' due to " + e.getMessage(), e); } } return object(sel); }
@Override public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression"); }
private reactor.event.selector.Selector fetchSelector(Selector selectorAnno, Object bean, Method method) { Object sel = parseSelector(selectorAnno, bean, method); try { switch (selectorAnno.type()) { case OBJECT: return object(sel); case REGEX: return regex(sel.toString()); case URI: return uri(sel.toString()); case TYPE: try { return type(Class.forName(sel.toString())); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e.getMessage(), e); } case JSON_PATH: return jsonPathSelector(sel.toString()); } } catch (EvaluationException e) { if (LOG.isTraceEnabled()) { LOG.trace("Creating ObjectSelector for '" + sel + "' due to " + e.getMessage(), e); } } return object(sel); }
@Override public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression"); }
logger.info("Could not find value for column '" + key + "': " + lastException.getMessage());
@Override public Object operate(Operation operation, @Nullable Object leftOperand, @Nullable Object rightOperand) throws EvaluationException { throw new EvaluationException("No operation overloaded by default"); }
logger.info("Could not find value for column '" + key + "': " + lastException.getMessage());
@Override public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException { throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression"); }