opensubscriber
   Find in this group all groups
 
Unknown more information…

d : dev@openejb.apache.org 11 February 2012 • 4:09PM -0500

Wrong CDI Interception in OpenEJB
by og0815

REPLY TO AUTHOR
 
REPLY TO GROUP



Hi everybody,

again I'm not 100% sure if I'm getting the spec right or found some bug.

Assume the following code.

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

---

@Interceptor
@MarkInterception
public class MarkedInterceptor {

    @AroundInvoke
    public Object manageTransaction(InvocationContext invocationContext)
throws Exception {
        System.out.println("Beginning Interceptor " + invocationContext);
        Object o = invocationContext.proceed();
        System.out.println("Ending Interceptor " + invocationContext);
        return o;
    }
}

---

@Stateless
public class BeanOne {

    @MarkInterception
    public void something() {
        System.out.println("BeanOne.something");
    }
    
}

---

@Stateless
public class BeanTwo {

    @Inject
    private BeanOne one;
        
    public void callOne() {
        one.something();
    }
}

---

Now if I call BeanTwo.callOne in a client I get the following expected
output:

Beginning Interceptor InvocationContext(operation=BUSINESS, target=BeanOne,
method=something)
BeanOne.something
Ending Interceptor InvocationContext(operation=BUSINESS, target=BeanOne,
method=something)

But, if I change the BeanTwo like this

@Stateless
public class BeanTwo {

    @Inject
    private BeanOne one;
    
    @MarkInterception
    public void doNothing() {
        
    }
    
    public void callOne() {
        one.something();
    }

}

the following happens:

Beginning Interceptor InvocationContext(operation=BUSINESS, target=BeanTwo,
method=callOne)
Beginning Interceptor InvocationContext(operation=BUSINESS, target=BeanOne,
method=something)
BeanOne.something
Ending Interceptor InvocationContext(operation=BUSINESS, target=BeanOne,
method=something)
Ending Interceptor InvocationContext(operation=BUSINESS, target=BeanTwo,
method=callOne)

Which means that also the callOne is now Intercepted. From my understanding
the Interceptor annotation at method level should only intercept the
selected method but in this case it looks like it has become a interceptor
for all methods.

Again am I doing something weird or is this a bug ?

Thanks,
Olli


--
View this message in context: http://openejb.979440.n4.nabble.com/Wrong-CDI-Interception-in-OpenEJB-tp4378502p4378502.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.