Search code examples
filterspring-xdspring-el

Spring XD - Logical operators in SpEL expression and filters


I would to create a filter like this

file --outputType=text/plain --dir=someDir --mode=lines | filter --expression='payload.contains(\"request url\") AND payload.contains(\"request method\")' | log

So, i would to visualize on the console the lines which contain request URL and request method.

I made this stream in according to this question

Unfortunatelly i've this error:

.... Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'expressionString' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1065E:(pos 17): unexpected escape character.

EDIT: i've deployed the stream via Flo


Solution

  • What version are you using? I just tried this with 1.3.1 with no problems...

    xd:>stream create foo --definition "tcp --outputType=text/plain | filter --expression='payload.contains(\"foo\") AND payload.contains(\"bar\")' | log" --deploy 
    
    $ telnet localhost 1234
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    abc
    foobar
    

    Result:

    2017-03-25T08:59:57-0400 1.3.1.RELEASE INFO xdbus.foo.1-1 sink.foo - foobar
    

    EDIT

    When using flo (admin UI), use '' instead of \" ...

    foo = tcp --outputType=text/plain | filter --expression='payload.contains(''foo'') AND payload.contains(''bar'')' | log