users@glassfish.java.net

InterceptorBinding does not work with embedded (EJB Container) GlassFish

From: <glassfish_at_javadesktop.org>
Date: Sun, 19 Sep 2010 15:30:36 PDT

Hi,

I am playing with GlassFish and JEE 6. And by following Arun Gupta's post (http://blogs.sun.com/arungupta/entry/totd_134_interceptors_1_1), I tried to experience the power of interceptors.

But I am currently facing with some problem of @InterceptorBinding (http://download.oracle.com/docs/cd/E17410_01/javaee/6/api/javax/interceptor/InterceptorBinding.htm) in my tests with different versions of glassfish-embedded-all (3.0, 3.0.1 and 3.1-b20).

=== the interceptorbinding type

@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({METHOD, TYPE})
public @interface Audited {
}

=== The audit interceptor interface
public interface Auditor {
  Object audit (InvocationContext context) throws Exception;
}

=== Simple implementation of Auditor by logging method invocation

@Interceptor
@Audited
public class SimpleTraceAuditor implements Auditor {
    @Override
    @AroundInvoke
    public Object audit(InvocationContext context) throws Exception {
       log.info ("Begin... ");
       Object result = context.proceed();
       log.info ("Successfully ended...");
       return result;
}

=== Simple Bean that should be intercepted

@Stateless
public class SimpleBean {
     @Override
    //_at_Audited --> does not work !
    @Interceptors({SimpleTraceAuditor.class}) // --> got trace
    public String saySomething() {
           return "should be traced";
    }
}

In my simple JUnit test, I created an embedded container by calling :
container = EJBContainer.createEJBContainer();
and looking for the SimpleBean with context.lookup ("java:global/classes/SimpleBean");

When I invoke the method simpleBean.saySomething(), the method is intercepted (got trace) only when I used the the annotation @Interceptors ({SimpleTraceAuditor.class}).

But when I used the annotation @Audited, the method is not intercepted (no trace). I got the same result by testing with

Do you have any ideas about it? Where am I wrong ?

Thanks for your help.

Best regards,

Hung
[Message sent by forum member 'quanghung_b']

http://forums.java.net/jive/thread.jspa?messageID=483099