0

I'm trying to pass some parameters from an interceptor to ejb context to be used later for logging. In the interceptor I'm doing this:

    @AroundInvoke
    public Object retrieveAdminData(InvocationContext context) throws Exception {
        User simulatingAdmin = ...;
        context.getContextData().put(Globals.ADMIN_USER_KEY, simulatingAdmin));

        return context.proceed();
    }

Then later in lifecycle I'm looking up ejb context and getting this value:

((SessionContext) new InitialContext().lookup("java:comp/EJBContext")).getContextData().get(Globals.ADMIN_USER_KEY);

Usually it works fine, but in some cases when I make a call from one bean to another, I get this exception when trying to get context data:

java.lang.IllegalStateException: Illegal call to EJBContext method. The bean is in running business method state. It cannot perform 'getting the Message Context for Stateless EJB' action(s). Refer to the EJB specification for more details.
    at weblogic.ejb.container.internal.BaseEJBContext.checkAllowedMethod(BaseEJBContext.java:93)
    at weblogic.ejb.container.internal.BaseEJBContext.checkAllowedToGetMessageContext(BaseEJBContext.java:291)
    at weblogic.ejb.container.internal.SessionEJBContextImpl.checkAllowedToGetMessageContext(SessionEJBContextImpl.java:210)
    at weblogic.ejb.container.internal.SessionEJBContextImpl.getMessageContextJAXWS(SessionEJBContextImpl.java:65)
    at weblogic.ejb.container.internal.SessionEJBContextImpl.getContextData(SessionEJBContextImpl.java:302)

All calls between beans are local calls. Could someone please point me into why it works for some beans, but not for others?

EDIT I've noticed that I stop being able to get ejb context if the call is from beans that are in different jars. Is this not allowed in EJB? Can I use ThreadLocal as a workaround?

Denis Tulskiy
  • 19,012
  • 6
  • 50
  • 68
  • can you clarify what you mean by "are in different jars". Are the jars within a same .ear? same war? in different deployment units? standalone jars? – eis Apr 04 '14 at 12:43
  • anyway, I think this has already been discussed in [this thread](http://stackoverflow.com/questions/8608349/using-ejbcontext-getcontextdata-is-this-safe?rq=1) – eis Apr 04 '14 at 12:46
  • @eis: they are in different jars in the same ear. That thread you mentioned quotes that ejb context is not shareable across business method invocations. But what makes local calls to beans from another jar a business method? – Denis Tulskiy Apr 04 '14 at 13:26

0 Answers0