Question

I am using Spring-Integration 3.0 and Spring-Integration Gemfire support. I wanted my inbound-channel-adapter to pick up the objects in cache as payload based on SpEL expression. I have written a custom expression evaluator class to check the properties of payload to select by the input adapter. The class code is as below:

@Component
public class GraphMatchingUtil {

public static boolean evaluate(NodeGraph nodeGraph){
    if(nodeGraph.getLastProcessedTS()!=null){

        if(nodeGraph.getLastProcessedTS().getTime() -  DateTimeUtil.createTimestamp().getTime() > 100000){
            return true;
        }
    }
    else{
        if(nodeGraph.getCreateTS().getTime() -  DateTimeUtil.createTimestamp().getTime() > 100000){
            return true;
        }
    }
    return false;
}

}

And the configuration code is as below

<int:spel-function id="match" class="com.equ.util.GraphMatchingUtil" method="evaluate(com.equ.bo.NodeGraph)"/>
<int-gfe:inbound-channel-adapter id="graphadapter" channel="reconchannel" region="cacheRegion" cache-events="CREATED, UPDATED" expression="@match(payload)==true"/>

However I am getting the below error after executing this code:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphadapter': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'payloadExpression' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 6): After parsing a valid expression, there is still more data in the expression: 'lparen(()'
     Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
     PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'payloadExpression' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 6): After parsing a valid expression, there is still more data in the expression: 'lparen(()'

Can anyone help me in understanding whats wrong with it?

After replacing @ with # I got this error:

   org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'payload' cannot be found on object of type 'com.gemstone.gemfire.internal.cache.EntryEventImpl'
Was it helpful?

Solution

You can't use payload in that expression - there is no message yet; that expression is "Expression to be evaluated to produce a value for the payload.", per the XSD documentation.

We should explain more clearly in the documentation that the root object for this expression is a Gemfire EntryEvent (javadocs here).

If you want to pass the entire event into your function, use #root.

expression="#match(#root)==true"

or you could do something like

expression="#match(key, oldValue, newValue)==true"

OTHER TIPS

Your issue is around the wrong reference to the SpEL function. Should be

expression="#match(payload)==true"

I meand the simbol # instead of @. Please, take a look into SpEL Reference

The @ is for bean reference, but # is for SpEL-function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top