2

There are lots of examples of how to write transformers etc in java but nothing about filters (except the script type filters, but I want to use a java method).

I'd like to create a custom java filter to filter the payload of a message from a source to a sink.

The examples of filters all refer to an expression.

(How) can I tell the context to execute a java method in a specified class as the expression?

Ron Tuffin
  • 53,859
  • 24
  • 66
  • 78

1 Answers1

6

Well, what you need to implement the custom Processor Module. Just follow with Custom Transformer sample from Spring XD Guilde

The custom Selector for filter:

public class MySelector implements MessageSelector {

     boolean accept(Message<?> message) {
      ...
    }
}

Module ctx myfilter.xml:

<channel id="input"/>

<filter input-channel="input" output-channel="output">
    <beans:bean class="custom.MySelector" />
</filter>

<channel id="output"/>

Package your class to the jar and place everything to the dir ${xd.home}/modules/processors/myfilter with structure:

/myfilter
   /config
      myfilter.xml
   /lib
      myfilter.jar

Test it like this:

xd:> stream create --name filtertest --definition "http | myfilter | log"
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Brilliant! Thanks @Artem. I'm a little new to spring integration and xd. I did see the Example you mentioned an was a bit frustrated that nothing was said about filters :) It was the MessageSelector implementation that did it for me. – Ron Tuffin Apr 01 '14 at 10:23