I am going to wrap an aspect around the Mule thread, IE. I would like to define @Around that will fire when something arrives in the Mule stream so that I can do my own statistics collection. I did not find a lightweight "Flow" class to wrap, but I saw that MessageReceiver is a good class, or at least implementations of this class.
However, I am not an expert in AspectJ, and I cannot get this to work. I have a @Aspect class with a method that looks like this.
@Around("execution(public * org.mule.api.transport.MessageReceiver+.*(..))") public Object addMonitor(ProceedingJoinPoint pjp) throws Throwable { System.out.println("Before"); Object object = pjp.proceed(); System.out.println("After"); return object; }
but I cannot get the Before / After lines to print when the methods from the HttpMessageReceiver . I set a debug point in my thread and see org.mule.transport.AbstractMessageReceiver.routeMessage(MuleMessage message) being called, which is the implementation of MessageReceiver , but I never see the call for my Aspect.
Is it possible to do this kind of Aspect in a Mule?
// EDIT: As I said, I am new to AspectJ and AOP, so I will say that I use spring in Mule to handle my @Aspect class. I have examples of this working on Spring-handled beans, but not on a regular POJO that is not managed by spring. My spring configuration looks like this:
<spring:beans> <context:component-scan base-package="com.example" /> <context:annotation-config /> <aop:aspectj-autoproxy /> </spring:beans>
source share