0 Replies Latest reply on Feb 15, 2012 12:23 PM by paul.robinson

    Internal invocation of EJB3 bean methods

    paul.robinson

      Hello,

       

      I have a scenario where I am using CDI to add an interceptor to an EJB method. The interceptor is as follows:

       

       

      @ServiceRequest
      @Interceptor
      public class ServiceRequestInterceptor
      {
          @AroundInvoke
          public Object intercept(InvocationContext ic) throws Throwable
          {
              Method serviceMethod = ic.getMethod();
              Object serviceImpl = ic.getTarget();
      
              ProtocolHandler protocolHandler = HandlerFactory.createInstance(serviceImpl, serviceMethod);
      
              return protocolHandler.proceed(ic);
          }
      
      }
      

       

      This registers the EJB implementation class and the intercepted method with my middleware. My middleware will then invoke methods on the EJB at various times. The problem I am having is that the EJB implementing instance is invoked directly, by my middleware, due to the way I am obtaining the reference. This doesn't seem like the right approach to me as it is bypassing the EJB3 interceptors. Also, the EJB may be re-allocated, pasivated, etc, which is going to result in odd behavior, I expect.

       

      Should I somehow look up the local stub to the EJB, based on what information I can gather from the implementation class; or is there a better way?

       

      Thanks,

       

      Paul.