Cannot intercept a method
bbarin Jan 24, 2011 4:30 PMHi
I've developed a simple aspect to measure the performance of my application, but althogh the deployment of the aspect in JBoss looks correct, the method that's aimed is not intercepted. I used the following approach:
- I have a performance.jar which contains the following aspect:
package com.agfa.ogpc.performance.aspects;
import com.agfa.ogpc.performance.dao.NeoDatisMessageProcessingDAO;
import com.agfa.ogpc.performance.dao.PerformanceDAO;
import org.jboss.aop.joinpoint.MethodInvocation;
import com.agfa.ogpc.performance.model.TimeElapsed;
public class MessageProcessingAspect {
public Object intercept(final MethodInvocation invocation) throws Throwable {
long startTime = System.currentTimeMillis();
try {
return invocation.invokeNext();
} finally {
long endTime = System.currentTimeMillis();
store(new TimeElapsed(startTime,endTime));
}
}
private void store(final TimeElapsed timeElapsed) {
PerformanceDAO<TimeElapsed> dao = new NeoDatisMessageProcessingDAO();
dao.persist(timeElapsed);
}
}
- I also have several .ears which are part of my application
- I deployed a file named performance-aop.xml in the deploy folder, that looks like:
<?xml version="1.0" encoding="UTF-8"?> <aop> <aspect class="com.agfa.ogpc.performance.aspects.MessageProcessingAspect"/> <bind pointcut="execution(* com.agfa.hap.bpe.components.db.BasicStatelessDBComponent->*(..))"> <around aspect="com.agfa.ogpc.performance.aspects.MessageProcessingAspect" name="intercept" /> </bind> </aop>
The application is deployed correctly and the -aop.xml is wellformed, but the application is not intercepted and I'm sure the method is being called (I debugged the code).
Then I have changed the syntax to intercept any method:
<?xml version="1.0" encoding="UTF-8"?> <aop> <aspect class="com.agfa.ogpc.performance.aspects.MessageProcessingAspect"/> <bind pointcut="execution(* *->*(..))"> <around aspect="com.agfa.ogpc.performance.aspects.MessageProcessingAspect" name="intercept" /> </bind> </aop>
But even after this change the aspect is not being called. I also tried to change the performance.jar to performance.aop and include a jboss-aop.xml within the META-INF folder, but without any success.
So, to summarize: I want to do some measures in an existing application running on JBoss 4.2.2. I couldn't find any example on that.
I suppose I have to enable the load time weaving mode, but turning on that option crashes the JBoss.
Any idea would be very appreciated.
Thanks,
Bruno