0 Replies Latest reply on Jul 24, 2014 1:42 PM by Rafael Sisto

    Pass data between Interceptors and Asynchronous methods

    Rafael Sisto Newbie

      Hi, I recently asked this question in stackoverflow with not so great responses, but finally arrived to a solution.


      I wanted to ask the experts in JBoss development if the final solution would have any imlpications or problems.

      I am using JBoss EAP 6.1


      Let's get to the point. I need to develop 2 interceptors, which will intercept 2 EJB 3.1 SLSB, something like this:


      public class StatelessA{
        public void methodA(){
      public class StatelessB{
        public void methodB(){...


      I will create some data in InterceptorA, which needs to be available in InterceptorB. The problem is that since InterceptorB and methodB run in a different thread as methodA, since this is an asynchronous invocation.

      Of course, my first thought was that I couldn't use a ThreadLocal variable, since these are not propagated to the asynchronous thread.


      I read the EJB 3.1 specification, which states that the security context is propagated, so I thought I could use that for sending my information.

      I solved it as follows:


      In InterceptorA:


      SecurityContext securityContext = SecurityContextAssociation.getSecurityContext();

      In InterceptorB:


      SecurityContext securityContext = SecurityContextAssociation.getSecurityContext();



      That way I can pass the info correctly from interceptorA to B. Can somebody tell me if there's a better solution?

      I know this implementation is coupled with JBoss server, but it decouples my application from the interceptors, which is what I want.