2 Replies Latest reply on Apr 13, 2015 2:17 AM by marembo2008

    Wildfly EJBClientInterceptor from one module is invoked from a different module

    marembo2008

      I am running wildfly 8.1 Server.

       

       

      I have several modules, each independently deployable as separate applications. Lets says:

       

       

      > 1. backend-ejb-module (deployed within an ear-application)

      > 2. frontend-war1-module (deployed as a standalone war application)

      > 3. frontend-war2-module (deployed as a standalone war application) ... And several more wars and webservice endpoints

       

       

      All these deployments are currently within the same wildfly 8.1 server.

      All the war modules use remote ejb calls to the backend-ejb-module and use the same frontend library which contains controllers and models.

       

       

      I have implemented an EJBClientInterceptor on my frontend components, using the jboss-ejb-client library.

       

       

          @Singleton

          @Startup

          public class FrontendEJBClientInterceptor implements EJBClientInterceptor {

              @PostConstruct

              void registerSelf() {

                  EJBClientContext.requireCurrent().registerInterceptor(0, this);

              }

        

              @Override

              public void handleInvocation(final EJBClientInvocationContext ejbcic) throws Exception {

                  //here there are frontend specifics SessionScoped,applicationscoped, or even requestscoped services that populates the invocation context.

              }

          }

       

       

      Everything works fine, but sometimes something weird happens, that an invocation of a backend-end EJB call (from the backend-ejb invocation itself) is intercepted by this interceptor. On the backend-module, there is of course no concept of SessionContext or RequestContext, which this interceptor injections may require, and hence i get the

       

       

      > ContextNotActiveException

       

       

      I definitely dont want this to happen.

      I was of the opinion that wildfly module loading should not be able to see other modules, unless the are explicitly declared, why is this happening.

       

       

      Any direction would be greatly appreciated.

        • 1. Re: Wildfly EJBClientInterceptor from one module is invoked from a different module
          jaikiran

          Can you post some relevant code where you are registering the interceptor and also the client EJB invocations?

          • 2. Re: Wildfly EJBClientInterceptor from one module is invoked from a different module
            marembo2008

            The interceptor is a stateless singleton bean, which registers itself as client interceptor on its @postconstruct method.

             

             

               

            @Singleton

            @Startup

            public class InvocationContextInterceptorService implements EJBClientInterceptor {
               private static final Logger LOG = Logger.getLogger(InvocationContextInterceptorService.class.getName());
               private static final String EJB_MODULE = "backend-ejb";
               @Inject
               @Any
               private Instance<InvocationContextPopulator> invocationContextPopulators;
               @Resource(lookup = "java:module/ModuleName")
               private String moduleName;
               @PostConstruct
               void registerSelf() {
                    EJBClientContext.requireCurrent().registerInterceptor(0, this);
               }
               @Override
               public void handleInvocation(final EJBClientInvocationContext ejbcic) throws Exception {
                    /*
                     * This is a workaround until we determine why this interceptor is being invocked from the backend!
                     */

                     if (!Objects.equals(moduleName, EJB_MODULE)) {

                     }

               }

            }

             

            This interceptor is only available within the war modules (as they are deployed independently of the ejb module)
            If i do not check on the EJB_MODULE name, the `InvocationContextPopulator` may require session context or request context, and hence when called from the backend, CDI will definitley complain with noactivecontextexception.

             

            The EJB interctions, moreoever, is through remote EJB (remoting as specified through the wildfly doc), the only shared libraries between the ejb-module and the war modules are the ejbremote interfaces.