0 Replies Latest reply on Jan 30, 2013 9:27 AM by Paul Robinson

    Obtaining an EJB proxy from a CDI Interceptor

    Paul Robinson Master

      Hello,

       

      I have a CDI interceptor that when placed on an EJB method (of a SLSB) enlists the EJB in a protocol for which it will later receive callbacks that enable it to participate in the protocol.

       

      Here's a simplified version of the code:

       

       

      @ServiceRequest
      @Interceptor
      public class ServiceRequestInterceptor {
      
          @AroundInvoke
          public Object intercept(InvocationContext ic) throws Throwable {
      
              Object targetInstance = ic.getTarget();
              //register targetInstance in the protcol
          }
      }
      

       

      Reflection is then used to make invocations on 'targetInstance' as the protocol progresses. The problem is that 'targetInstance' is the actual java instance, so invocations bypass the whole EJB stack. I imagine causes problems for instance management as I'm accessing the bean without the EJB container knowing. But, the more immediate problem I'm seeing is that this approach prevents EJB features like CMT from working.

       

      I think the solution to my problem is to somehow lookup the right EJB proxy in the interceptor. However, I'm unsure how to do this as I won't know the details such as the appName or moduleName. The interceptor does have access to the .class of the bean implementation, if this helps?

       

      Any ideas would be much appreciated.

       

      Paul.