14 Replies Latest reply on Mar 27, 2008 5:47 PM by Anil Saldanha

    Determine whether an invocation is local or remote

    Anil Saldanha Master

      For ejb3 security integration, it is important for me to figure out whether an invocation is remote or local such that I can pick the appropriate security context. For remote invocation, I pick the one from the invocation.

      Well, one solution would be if invocation.getsecuritycontext == null, then it is local. But I am unsure this would be the best.

      Looking at the ejb3 codebase and considering various usecases, this is the code that I have copy/pasted to determine whether an invocation is local.

       * Check whether an invocation is local or remote
       * @param mi method invocation
       * @return true - local call
       public boolean isLocalCall(MethodInvocation mi)
       InvokerLocator locator = (InvokerLocator) mi.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR);
       return locator == null ||
       mi.getMetaData(IsLocalInterceptor.IS_LOCAL,IsLocalInterceptor.IS_LOCAL) != null;

      Another alternative would be setting a flag on the invocation.

      Carlo, can you suggest a better solution?