/** * Verifies behavior requested in SPR-9621. */ @Test public void customMethodFilter() { StandardEvaluationContext context = new StandardEvaluationContext(); // Register a custom MethodResolver... List<MethodResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomMethodResolver()); context.setMethodResolvers(customResolvers); // or simply... // context.setMethodResolvers(new ArrayList<MethodResolver>()); // Register a custom MethodFilter... MethodFilter filter = new CustomMethodFilter(); try { context.registerMethodFilter(String.class, filter); fail("should have failed"); } catch (IllegalStateException ise) { assertEquals( "Method filter cannot be set as the reflective method resolver is not in use", ise.getMessage()); } }
context.setRootObject(new TestObject()); LocalFilter filter = new LocalFilter(); context.registerMethodFilter(TestObject.class,filter); context.registerMethodFilter(TestObject.class,null);//clear filter context.setRootObject(new TestObject()); expr = (SpelExpression) parser.parseExpression("doit(1)");
private void prepareEvaluationContext() throws Exception { StandardEvaluationContext context = getEvaluationContext(false); Class<?> targetType = AopUtils.getTargetClass(this.targetObject); if (this.method != null) { context.registerMethodFilter(targetType, new FixedMethodFilter(this.method)); if (this.expectedType != null) { Assert.state(context.getTypeConverter() .canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType), () -> "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); } } else { AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), () -> "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); context.registerMethodFilter(targetType, filter); } context.setVariable("target", this.targetObject); context.registerFunction("requiredHeader", ParametersWrapper.class.getDeclaredMethod("getHeader", Map.class, String.class)); }
private void prepareEvaluationContext(StandardEvaluationContext context, Object method, Class<? extends Annotation> annotationType) { Class<?> targetType = AopUtils.getTargetClass(this.targetObject); if (method instanceof Method) { context.registerMethodFilter(targetType, new FixedMethodFilter((Method) method)); if (expectedType != null) { Assert.state( context.getTypeConverter().canConvert( TypeDescriptor.valueOf(((Method) method).getReturnType()), TypeDescriptor.valueOf(expectedType)), "Cannot convert to expected type (" + expectedType + ") from " + method); } } else if (method == null || method instanceof String) { AnnotatedMethodFilter filter = new AnnotatedMethodFilter(annotationType, (String) method, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), "Cannot convert to expected type (" + expectedType + ") from " + method); context.registerMethodFilter(targetType, filter); } context.setVariable("target", targetObject); }
private void prepareEvaluationContext() throws Exception { StandardEvaluationContext context = getEvaluationContext(false); Class<?> targetType = AopUtils.getTargetClass(this.targetObject); if (this.method != null) { context.registerMethodFilter(targetType, new FixedMethodFilter(this.method)); if (this.expectedType != null) { Assert.state(context.getTypeConverter() .canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), this.expectedType), "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); } } else { AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); context.registerMethodFilter(targetType, filter); } context.setVariable("target", this.targetObject); context.registerFunction("requiredHeader", ParametersWrapper.class.getDeclaredMethod("getHeader", Map.class, String.class)); }
private void prepareEvaluationContext(StandardEvaluationContext context, Object method, Class<? extends Annotation> annotationType) { Class<?> targetType = AopUtils.getTargetClass(this.targetObject); if (method instanceof Method) { context.registerMethodFilter(targetType, new FixedMethodFilter((Method) method)); if (expectedType != null) { Assert.state( context.getTypeConverter().canConvert( TypeDescriptor.valueOf(((Method) method).getReturnType()), TypeDescriptor.valueOf(expectedType)), "Cannot convert to expected type (" + expectedType + ") from " + method); } } else if (method == null || method instanceof String) { AnnotatedMethodFilter filter = new AnnotatedMethodFilter(annotationType, (String) method, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), "Cannot convert to expected type (" + expectedType + ") from " + method); context.registerMethodFilter(targetType, filter); } context.setVariable("target", targetObject); }