Reputation: 3356
I'm trying to use the instanceof operator in a SpEL expression in a filter for a stream. I'm trying the following:
stream create myStream --definition "tap:job:jobName > filter --expression='payload instanceof T(com.package.name.event.SomeEvent)' | log --deploy
I am publishing my own event to the xd.job.aggregatedEvents channel. My intention is to log only my SomeEvent's by filtering using the instanceof operator.
The problem is I am getting the following error:
org.springframework.expression.spel.SpelEvaluationException: EL1005E:(pos 0): Type cannot be found 'com.package.name.event.SomeEvent'
My question is can anyone advise me as to the proper syntax for instanceof in SpEL expressions? Or if this is correct syntax then what the problem might be?
Upvotes: 1
Views: 778
Reputation: 121507
According to the StackStrace - Type cannot be found
and the logic from the StandardTypeLocator
:
try {
return ClassUtils.forName(nameToLookup, this.classLoader);
}
catch (ClassNotFoundException ey) {
// try any registered prefixes before giving up
....
throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName);
You just end up with the issue like ClassNotFoundException
. So, your jar with the com.package.name.event.SomeEvent
is outside of the XD CLASSPATH.
You can compare it using literal:
--expression='payload.class.name == '''com.package.name.event.SomeEvent''''
Or just place your jar to the dirt container
classpath.
From other side it is always a bad idea to use domain-specific types for messaging systems. You should think how to overcome that using standard supported types and replace the check condition to some value (in the standard type) to the message headers.
Upvotes: 2