I needed to log all the calls to all methods made to a certain EJB (because I wanted to know which methods were called from which place). The reason was locks I received on a stateless session bean. I could use a debugger, but because I'm talking about a lot of functions and a lot of calls, I created a LogInterceptor:
package be.jochenhebbrecht.ejb.interceptor; import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; public class LogInterceptor{ @AroundInvoke public Object intercept(InvocationContext context) throws Exception { // Log to console before executing method System.out.println("Entering method:" + context.getMethod().getName()); // Execute method Object result = context.proceed(); // Log to console after executing method System.out.println("Leaving method: " + context.getMethod().getName() ); return result; } }
To use the interceptor, simply add the following code
Add new comment