Announcement Announcement Module
No announcement yet.
publishing-interceptor extra messages explanation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • publishing-interceptor extra messages explanation


    I would greatly appreciate it if someone would explain why my publishing-interceptor defaultChannel below is getting two of my TestBean messages; i was only expecting to see the echoChannel message that was published due to my interceptor method getting called.

    console output:

    18:16:58.001 INFO [main][simple.Main] PRE-TEST
    18:16:58.353 INFO [main][simple.TestBean] DEFAULT CHANNEL INGORED: [email protected][class simple.TestBean]
    18:16:58.366 INFO [main][simple.TestBean] DEFAULT CHANNEL INGORED: [email protected][class simple.TestBean]
    18:16:58.381 INFO [main][simple.TestBean] ECHO CHANNEL RECEIVED: Echoing: Hello!
    18:16:58.382 INFO [main][simple.Main] POST-TEST


    <beans:bean id="testBean" class="simple.TestBean" />

    <channel id="defaultChannel"/>
    <channel id="echoChannel"/>
    <channel id="outputChannel"/>

    <aop:aspectj-autoproxy proxy-target-class="true"/>

    <aop:advisor advice-ref="interceptor" pointcut="bean(testBean)" />

    <publishing-interceptor id="interceptor" default-channel="defaultChannel">
    <method pattern="echo" payload="'Echoing: ' + #return" channel="echoChannel" />

    <service-activator input-channel="echoChannel" output-channel="outputChannel" ref="testBean" method="inspect" />
    <service-activator input-channel="defaultChannel" output-channel="outputChannel" ref="testBean" method="ignore" />


    public class TestBean {
    private static final Logger LOGGER = Logger.getLogger(TestBean.class);

    public String echo(String str) {
    return str;

    public void inspect(def msg) {"ECHO CHANNEL RECEIVED: " + msg);

    public void ignore(def msg) {"DEFAULT CHANNEL INGORED: " + msg);


    public static void main(final String... args) {

    final AbstractApplicationContext context =
    new ClassPathXmlApplicationContext("classpath:simple-context.xml");

    final TestBean tester = context.getBean("testBean", TestBean.class);"PRE-TEST");

    Last edited by asanderson; Aug 10th, 2012, 06:45 PM.

  • #2
    Well, I hate replying to my own thread so soon, but I discovered something interesting. If I convert either my TestBean.groovy or my Main.groovy or both to java, the extra messages don't get created; however, if both are groovy, the extra messages are generated.

    BTW, I'm using spring-integration 2.2.0.M3.



    • #3

      publishing-interceptor defaultChannel below is getting two of my TestBean
      It heppens because inside the GDK before each method invocation is called GroovyObject.getMetaClass().
      So, in your case it works like this:
      1. Groovy see invocation of TestBean#echo he calls getMetaClass() on it.
      2. getMetaClass() doesn't have publishing-interceptor mapping, so it publish Message to defaultChannel.
      3. On the defaultChannel you place the same class and calling getMetaClass() on his method ignore repeates step 2.

      The woraround for you:
      HTML Code:
      <publishing-interceptor id="interceptor" default-channel="defaultChannel">
      		<method pattern="echo" payload="'Echoing: ' + #return" channel="echoChannel"/>
      		<method pattern="getMetaClass" channel="nullChannel"/>
      Calling getMetaClass will be intercepted to nullChannel.

      Artem Bilan


      • #4
        Outstanding explanation!

        I greatly appreciate your feedback.

        Many thanks!