5 Replies Latest reply on May 26, 2006 5:22 AM by jpyorre

    Same JNDI Lookup from different MBeans (but same ClassLoader

    jpyorre

      Hello,


      I'm trying to perform a JNDI lookup for an EJB3 stateless session bean (local interface) from an MBean. This works OK from one MBean, but when I create another MBean (the MBean creation routine is executed by the first MBean) by

      this.getServer().createMBean(myClassName, myObjectName);

      and run exactly the same JNDI lookup routine from the created MBean, I get:


      ...
      Caused by: javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: myproject.myClass (no security manager: RMI class loader disabled)]
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       ... 37 more
      Caused by: java.lang.ClassNotFoundException: myproject.myClass (no security manager: RMI class loader disabled)
       at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:531)
       at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628)
       at org.jboss.system.JBossRMIClassLoader.loadProxyClass(JBossRMIClassLoader.java:82)
       at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294)
       at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238)
       at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1494)
       at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1457)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
       at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:652)
       ... 41 more
      


      I checked that both MBeans use the same ClassLoader (org.jboss.mx.loading.UnifiedClassLoader3) instance so this can't be the issue. Both MBeans extend ServiceMBeanSupport.

      What is the significant difference between these two MBeans as they both run in the same ClassLoader and execute the same JNDI lookup?


      Regards,

      Jussi Pyörre

        • 1. Re: Same JNDI Lookup from different MBeans (but same ClassLo
          jpyorre

          Forgot to tell that I'm using JBoss AS 4.0.4GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)

          • 2. Re: Same JNDI Lookup from different MBeans (but same ClassLo
            jpyorre

            Still one more observation:

            If the MBean is deployed using jboss-service.xml, JNDI lookup works. If the same MBean is deployed using createMBean method from another MBean, an exception occurs.

            So, the way the MBean is deployed seems to make the difference.

            • 3. Re: Same JNDI Lookup from different MBeans (but same ClassLo
              jpyorre

              The monologue continues: I have managed to resolve that the problem is in the context class loader.

              When invoking methods in MBeans deployed by the SARDeployer the context class loader is UnifiedClassLoader3 instance defined by the loader-repository element in jboss-service.xml.

              When an MBean creates another MBean, the Context ClassLoader is set to some other when invoking a method in the MBean.


              How can I set the context classloader of the MBean? I can easily perform

              Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader())
              


              but this is not an elegant solution as the context class loader should be automatically set (as it is when deploying an MBean using SARDeployer).

              • 4. Re: Same JNDI Lookup from different MBeans (but same ClassLo
                starksm64

                There is more than one createMBean signature. Think about those that take a loaderName.

                • 5. Re: Same JNDI Lookup from different MBeans (but same ClassLo
                  jpyorre

                  The loaderName for createMBean is not directly available, so I use the following trick (because UnifiedClassLoader3 is implementing an MBean interface):

                   ObjectName loaderName = ObjectName.getInstance("my.dot.com:service=MyClassLoader");
                  
                   if (!getServer().isRegistered(loaderName)) {
                   getServer().registerMBean(this.getClass().getClassLoader(), loaderName);
                   }
                  


                  I suppose this is the only way to do it, bacause all methods that would accept ClassLoader instance directly are protected in MBeanServerImpl.

                  Thanks for the advice, Scott!


                  Regards,

                  Jussi