9 Replies Latest reply on Nov 15, 2006 5:36 PM by Giovanni Tirino

    JNDI Newbie - Please help !!!

    Giovanni Tirino Newbie

      This is my code:

      package test.main;
      import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
      import java.util.*;
      import javax.management.*;
      import javax.naming.*;

      public class TestMain {
      public static void main(String args[]) throws Exception {
      Properties props=new Properties(); props.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      props.put(InitialContext.PROVIDER_URL, "jnp://localhost:1099"); props.put(InitialContext.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
      InitialContext ic = new InitialContext(props);
      Hashtable icHash = ic.getEnvironment();
      Enumeration enumHash = icHash.keys();
      System.out.println("Key num: " + icHash.size());
      while(enumHash.hasMoreElements()) {
      Object nextIc = enumHash.nextElement();
      System.out.print("Keys: "+nextIc.toString());
      System.out.println(" = "+icHash.get(nextIc));
      System.out.println("Initial Context ok: ");
      NamingEnumeration names = ic.list("");
      System.out.println("Has More: " + names.hasMoreElements());
      while(names.hasMoreElements()) {
      System.out.println((String) names.nextElement().toString());
      RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/invoker/RMIAdaptor");
      System.out.println("RMIAdaptor ok: "+server.getMBeanCount());
      System.out.println("Name: " + server.getDefaultDomain());

      ===> ObjectName nameTest = new ObjectName("jboss:service=JNDIView");

      MBeanInfo info = server.getMBeanInfo(nameTest);
      System.out.println("Name: " + info.getClassName());

      This is the error where arrow is:

      Exception in thread "main" java.lang.NullPointerException
      at java.io.ObjectStreamClass.setClass(libgcj.so.7)
      at java.io.ObjectInputStream.readClassDescriptor(libgcj.so.7)
      at java.io.ObjectInputStream.readObject(libgcj.so.7)
      at java.io.ObjectInputStream.readObject(libgcj.so.7)
      at java.rmi.MarshalledObject.get(libgcj.so.7)
      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:119)
      at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:227)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:167)
      at org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor.invoke(InvokerAdaptorClientInterceptor.java:51)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
      at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:59)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:86)
      at $Proxy0.getMBeanInfo(Unknown Source)
      at test.main.TestMain.main(TestMain.java:50)

      PLEASE HELP !!!!

      WHERE I AM WRONG ???

      Thank a lot

        • 1. Re: JNDI Newbie - Please help !!!
          Peter Johnson Master

          Which version of JBoss are you using?

          Are you using the correct jbossall-client.jar that matches with the server?

          I used 4.0.5, and here is my output:

          Key num: 4
          Keys: jnp.parsedName =
          Keys: java.naming.provider.url = localhost:1099
          Keys: java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory
          Keys: java.naming.factory.url.pkgs = org.jboss.naming:org.jnp.interfaces
          Initial Context ok:
          Has More: true
          MyTxController: $Proxy72
          MyCustomer: $Proxy60
          TopicConnectionFactory: org.jboss.naming.LinkRefPair
          jmx: org.jnp.interfaces.NamingContext
          MyAccountController: $Proxy68
          HTTPXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
          ConnectionFactory: org.jboss.mq.SpyConnectionFactory
          UserTransactionSessionFactory: $Proxy12
          HTTPConnectionFactory: org.jboss.mq.SpyConnectionFactory
          MyTx: $Proxy62
          XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
          UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
          UILXAConnectionFactory: javax.naming.LinkRef
          UIL2XAConnectionFactory: javax.naming.LinkRef
          MyNextId: $Proxy63
          MyAccount: $Proxy61
          queue: org.jnp.interfaces.NamingContext
          topic: org.jnp.interfaces.NamingContext
          bank-client: org.jnp.interfaces.NamingContext
          console: org.jnp.interfaces.NamingContext
          MyCustomerController: $Proxy70
          UIL2ConnectionFactory: javax.naming.LinkRef
          HiLoKeyGeneratorFactory: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGenerato
          UILConnectionFactory: javax.naming.LinkRef
          QueueConnectionFactory: org.jboss.naming.LinkRefPair
          UUIDKeyGeneratorFactory: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGenerato
          RMIAdaptor ok: 522
          Name: jboss
          Name: org.jboss.mx.modelmbean.XMBean

          • 2. Re: JNDI Newbie - Please help !!!
            Giovanni Tirino Newbie

            Thanks for your answer.

            I am using jboss 4.0.2 with jdk 1.4.2

            I am really newbie on jboss applications...maybe I am wrog with some setiings (eg: classpath) ?

            Thank a lot


            • 3. Re: JNDI Newbie - Please help !!!
              Jerry Gauthier Apprentice

              Do all methods fail for your object name? Instead of using server.getMBeanInfo(), try
              Object retval = server.invoke(nameTest, "listXML", null, null);

              This should provide a listing of the JNDI tree contents.

              • 4. Re: JNDI Newbie - Please help !!!
                Giovanni Tirino Newbie


                Yes it works !!!

                What could be the problem with getMBeanInfo ??

                • 5. Re: JNDI Newbie - Please help !!!
                  Jerry Gauthier Apprentice

                  I think the problem is that you're working remotely so you're accessing proxies. Your original code will probably work as is if you execute it from a servlet rather than a remote client.

                  Working remotely, you need to use methods such as server.invoke() and server.getAttribute() to interact with the mbeans of interest.


                  • 6. Re: JNDI Newbie - Please help !!!
                    Giovanni Tirino Newbie


                    What do you mean with "remotely" ? I am on the same machine. I am trying to use RMI to query the Server following the Jboss guide, but this example doesn't work.

                    Maybe I don't understand the correct use of RMI !!!


                    • 7. Re: JNDI Newbie - Please help !!!
                      Jerry Gauthier Apprentice

                      By "remotely", I mean that you're not running in the same JVM. If you run your code from a servlet deployed to JBoss, you'll be in the same JVM and I suspect your code will work properly.

                      • 8. Re: JNDI Newbie - Please help !!!
                        Peter Johnson Master


                        The code you provided works as is (which is why I showed you the output from when I ran it). So the problem must be configuration. Here is the command line I used to run it:

                        java -cp .;$JBOSS_HOME/client/jbossall-client.jar test.main.TestMain

                        • 9. Re: JNDI Newbie - Please help !!!
                          Giovanni Tirino Newbie

                          Thanks Peter. Thanks Jerry

                          It was a misconfiguration in my Eclipse (using another JVM installed !!!).

                          Very good.

                          Thank a lot !!