1

I've the following case:

@Interceptors(MyInterceptClass.class)
public void ejbMethod1()
{

}


@Interceptors(MyInterceptClass.class)
public void ejbMethod2()
{
    ejbMethod1();
}

Is calling ejbMethod2 causes TWO interceptor calls to be executed?

Thanks.

Muhammad Hewedy
  • 29,102
  • 44
  • 127
  • 219

1 Answers1

0

I'll assume you mean @Interceptors (plural) annotation which defines the interceptor class which will be invoked upon annotated method invocation. @Interceptor annotation (singular) is for annotating a class which is an interceptor.

If so, then short answer is: no.

The interceptor is executed by the container. If your method invocation will not go through the container, then it will not be intercepted.

Therefore the following call to ejbMethod1():

@Interceptors(MyInterceptClass.class) 
public void ejbMethod2() {
    ejbMethod1(); 
}

won't activate the MyInterceptClass as it's the local call (non-EJB one).

If you'd like to call the interceptor once again, you should use business interface, so something like:

// Somewhere in the class
@Resource
SessionContext ctx;

@Interceptors(MyInterceptClass.class) 
public void ejbMethod2() {
    // This is explicit call which will go through the EJB Container
    ctx.getBusinessObject(YourEJBClass.class).ejbMethod1();
}

This will make the EJB-aware call and will hit the interceptor while invoking ejbMethod1().

Piotr Nowicki
  • 17,914
  • 8
  • 63
  • 82