Skip to content

Category Archives: EJB3

Example Interceptor in Seam, EJB3

It’s insanely easy to write an interceptor in EJB3. Here’s a tutorial/example code for an interceptor which collects statistics info around a method invocation.
import java.util.Collection;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StatisticsInterceptor {
private static final Log log = LogFactory
.getLog(StatisticsInterceptor.class);

@AroundInvoke
@SuppressWarnings("unchecked")
public Object intercept(InvocationContext ctx) throws Exception {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Object result = ctx.proceed();
log.debug("Statistics for "
+ ctx.getMethod().getDeclaringClass().getSimpleName() [...]