Results 1 to 4 of 4

Thread: publishing-interceptor extra messages explanation

  1. #1
    Join Date
    Mar 2012
    Posts
    9

    Default publishing-interceptor extra messages explanation

    Greetings!

    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: groovy.lang.MetaClassImpl@44ac5e[class simple.TestBean]
    18:16:58.366 INFO [main][simple.TestBean] DEFAULT CHANNEL INGORED: groovy.lang.MetaClassImpl@44ac5e[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

    simple-context.xml:

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

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

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

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

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

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


    TestBean.groovy:

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

    public String echo(String str) {
    return str;
    }

    public void inspect(def msg) {
    LOGGER.info("ECHO CHANNEL RECEIVED: " + msg);
    }

    public void ignore(def msg) {
    LOGGER.info("DEFAULT CHANNEL INGORED: " + msg);
    }
    }

    Main.groovy:

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

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

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

    LOGGER.info("PRE-TEST");
    tester.echo("Hello!");
    LOGGER.info("POST-TEST");

    }
    Last edited by asanderson; Aug 10th, 2012 at 05:45 PM.

  2. #2
    Join Date
    Mar 2012
    Posts
    9

    Default

    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.

    Thoughts?

  3. #3
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    632

    Default

    Hello

    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"/>
    	</publishing-interceptor>
    Calling getMetaClass will be intercepted to nullChannel.

    Cheers,
    Artem Bilan

  4. #4
    Join Date
    Mar 2012
    Posts
    9

    Default

    Outstanding explanation!

    I greatly appreciate your feedback.

    Many thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •