1

I am quite new to MVEL. What I am trying to achieve is to log input and outputs of every function in an expression.

For example, having the following expression

h.function1('value1') != h.function2('value2') 

what I am trying to log is the input and output values of function1 and function2. I read about Interceptors. If I do undestand right, to add and interceptor I need to rewrite the above expression as the following.

@Intercept h.function1('value1') != @Intercept h.function2('value2')

However, I cannot force my users to add the @Intercept annotation.

Which is the best way to accomplish this task? Have I to resume Spring AOP? :(

riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106

1 Answers1

1

It's not @Intercept but the name of intercept you put in map. Bellow is @test annotation. Please check detail here https://github.com/mvel/mvel/blob/master/src/test/java/org/mvel2/tests/core/CoreConfidenceTests.java

interceptors.put("test",
        testInterceptor);

 executeExpression(compileExpression("@test System.out.println('MIDDLE');",
        null,
        interceptors));
nguyentran
  • 458
  • 2
  • 14
  • Thanks for your response. However you confirmed me that is mandatory to put an annotation into the expression to accomplish the task using exclusively MVEL, don't you? – riccardo.cardin Mar 15 '17 at 07:32
  • 1
    Yep, there are doc in source code (check doxygen for method compileExpression) http://www.programcreek.com/java-api-examples/index.php?source_dir=mvel-master/src/main/java/org/mvel2/MVEL.java – nguyentran Mar 15 '17 at 09:21