3 Replies Latest reply on Aug 13, 2008 5:31 AM by jaikiran pai

    4.2.2 MBean getClientHost java.rmi.server.ServerNotActiveExc

    Guy Rouillier Newbie

      I found the following very old post but thought I'd start a new one after all this time.

      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=20245

      I'm upgrading some code that has run under 2.4.3 and 3.2.7 to run under 4.2.2. The upgrade process was fairly painless. So far, I've only run into this one runtime issue. The architecture consists of Java clients invoking a session EJB which exists merely to forward the calls to an MBean; there's a one-to-one mapping of methods in the EJB to methods in the MBean (plus the MBean has additional code.) This has worked fine in the previous JBoss versions. I'm running both 3.2.7 and 4.2.2 on JDK 1.5.

      With 4.2.2, I'm getting the exception "java.rmi.server.ServerNotActiveException: not in a remote call" when the MBean invokes java.rmi.server.UnicastRemoteObject.getClientHost(). If I catch this exception and just set the client host IP address to "127.0.0.1", everything continues normally: the MBean does what it is supposed to do and returns the correct result.

      What has changed in version 4 since versions 2 and 3 to produce this ServerNotActiveException? Is this happening because the session EJB is the code contacting the MBean, and not the originating client? Did this work before because EJBs were maintaining the client context and now 4.2.2 they are not? Perhaps this is an aspect of EJB3?

      Unfortunately, the API implemented by the EJB and MBean consists of over 60 methods, so retrofitting a separate parameter to each of them to contain the client's IP address is not really feasible.

      Thanks for all ideas.

        • 1. Re: 4.2.2 MBean getClientHost java.rmi.server.ServerNotActiv
          Guy Rouillier Newbie

          Ok, following the post that I reference, I was able to implement a client interceptor to capture the client's IP address and add it to the invocation object using setValue(). Then I was able to create a server interceptor, modeled after the LogInterceptor (i.e., extends from AbstractInterceptor), which can retrieve the IP address from the invocation object using getValue(). So far, so good.

          Now, how does that help me? I need to get that value into something that the EJB business method can access, which then needs to pass it on to a corresponding MBean method, again in some transparent fashion. That is, I don't want to modify the 60 business methods in the stateless session EJB or the corresponding 60 business methods in the MBean. Ideally, the MBean could get hold of the invocation object, but I don't know if that is possible.

          Thanks.

          • 2. Re: 4.2.2 MBean getClientHost java.rmi.server.ServerNotActiv
            Guy Rouillier Newbie

            Ok, I finally got this figured out. For those who may stumble upon this thread, here is a quick summary of what I had to do to get this to work. If someone can tell me where to post a code sample, I'll do that when I get some time:

            (1) Implement a client interceptor that captures the client IP address in a static initialization block:

            aIpAddr = InetAddress.getLocalHost().getHostAddress();
            


            Then, in the invoke method, add this value to the invocation object:

            invocation.setValue("client_ip_addr", aIpAddr);
            


            This code runs in the client VM.

            (2) Implement a container interceptor to copy the captured value into the server VM. In order to have this value retrievable by an EJB and then by MBeans called by that EJB, you'll need a ThreadLocal variable. In the code below ClientIpAddress manages a ThreadLocal variable.

            String aIpAddr = (String) mi.getValue("client_ip_addr");
            ClientIPAddress.set(aIpAddr);
            


            (3) ThreadLocal variables are managed as class static variables, at least in my simple case (and in the Sun Java documentation.) So, to use the value in an EJB or MBean, you just reference it. This assumes the EJB and the MBean are running in the same VM. If not, I suppose you'll have to figure out some way to pass along the value to the target VM, I imagine through another pair of invokers.

            ClientIPAddress.get()
            


            I'd like to say a sincere thanks to myself for helping me through this ;).

            • 3. Re: 4.2.2 MBean getClientHost java.rmi.server.ServerNotActiv
              jaikiran pai Master

               

              "guy_rouillier" wrote:
              If someone can tell me where to post a code sample, I'll do that when I get some time:



              The JBoss Wiki http://wiki.jboss.org/wiki is a good place.

              I guess, you can add this to the "Why do I" section at http://wiki.jboss.org/wiki/JBossFrequentlyAskedQuestions