3 Replies Latest reply on Dec 13, 2007 10:09 AM by jaikiran pai

    Standalone client getting errors while attempting to access

    Jacques Gonzalez Newbie

      How can a standalone client access JBoss JNDI bindings content?

      The standalone client code below works find with other application servers (WebLogic, Sun) but not with JBoss.

      The first error when running the client is:

      java.lang.ClassNotFoundException: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory (no security manager: RMI class loader disabled)]

      After adding a security manager and a policy file to the standalone client there is a second error:

      java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

      ____________________

      Below are the code and the stacktraces of the two versions of the standalone client one blank the other with security manager settings.

      Standalone client without security manager settings:


      package test;

      import java.util.Properties;

      import javax.naming.Binding;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingEnumeration;
      import javax.naming.NamingException;

      public class ListJNDIBindings {

      public static void main(String[] args) {

      Properties props = new Properties();
      props.put(Context.INITIAL_CONTEXT_FACTORY, org.jnp.interfaces.NamingContextFactory.class.getName());
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

      try {
      Context context = new InitialContext(props);
      NamingEnumeration ne = context.listBindings("");
      while (ne.hasMore()) {
      System.out.println(ne.nextElement());
      }
      } catch (NamingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      }

      Stacktrace:

      javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory (no security manager: RMI class loader disabled)]
      at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:966)
      at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:915)
      at javax.naming.InitialContext.listBindings(InitialContext.java:406)
      at test.ListJNDIBindings.main(ListJNDIBindings.java:27)
      Caused by: java.lang.ClassNotFoundException: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory (no security manager: RMI class loader disabled)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:371)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
      at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
      at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
      at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1544)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
      at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
      at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
      at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:962)
      ... 3 more

      Standalone client with security manager settings:

      Policy file:

      grant {
      permission java.security.AllPermission;
      };


      Standalone client code:

      package test;

      import java.rmi.RMISecurityManager;
      import java.util.Properties;

      import javax.naming.Binding;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingEnumeration;
      import javax.naming.NamingException;

      public class ListJNDIBindings {

      public static void main(String[] args) {

      System.setProperty("java.security.policy", "client.policy");
      if (System.getSecurityManager() == null)
      System.setSecurityManager(new RMISecurityManager());

      Properties props = new Properties();
      props.put(Context.INITIAL_CONTEXT_FACTORY, org.jnp.interfaces.NamingContextFactory.class.getName());
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

      try {
      Context context = new InitialContext(props);
      NamingEnumeration ne = context.listBindings("");
      while (ne.hasMore()) {
      System.out.println(ne.nextElement());
      }
      } catch (NamingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      }

      Stacktrace:

      javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: java.security.AccessControlException: access denied (java.net.SocketPermission 230.0.0.4 connect,accept,resolve) [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)]]
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)
      at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:922)
      at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:915)
      at javax.naming.InitialContext.listBindings(InitialContext.java:406)
      at test.ListJNDIBindings.main(ListJNDIBindings.java:27)
      Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)]
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
      ... 4 more
      Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
      at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
      at java.security.AccessController.checkPermission(AccessController.java:427)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
      at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
      at java.net.Socket.connect(Socket.java:513)
      at java.net.Socket.connect(Socket.java:469)
      at java.net.Socket.(Socket.java:366)
      at java.net.Socket.(Socket.java:266)
      at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:84)
      at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:77)
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244)
      ... 5 more




        • 1. Re: Standalone client getting errors while attempting to acc
          jaikiran pai Master

           

          java.lang.ClassNotFoundException: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory (no security manager: RMI class loader disabled)]


          All you have to do is, make sure that the standalone client has the appropriate JBoss jar file(s) in its classpath. You dont have to do anything related to the security manager. I usually place the jbossall-client.jar (present in %JBOSS_HOME%/client folder) file in a standalone client's classpath. I am not sure which jar file this org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory class belongs to. You might have to search through the jboss jar files and find the appropriate one.

          • 2. Re: Standalone client getting errors while attempting to acc
            Jacques Gonzalez Newbie

            Thanks for your help but it doesn't work yet.

            All you have to do is, make sure that the standalone client has the appropriate JBoss jar file(s) in its classpath.


            I found the HiLoKeyGeneratorFactory class in a uuid-key-generator.sar directory under the default deployment directory. I also had to add the jboss-server.jar.

            It looks like a JBoss standalone client cannot browse the JNDI binding because of a dependency of the client jars on a sar and jboss-server.jar, which in turns throws an exception complaining about "No 'jboss' MBeanServer found!".

            Any other ideas?

            Stack traces below:

            Error with jbossall-client.jar added to classpath:

            javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory (no security manager: RMI class loader disabled)]
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:966)
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:915)
            at javax.naming.InitialContext.listBindings(InitialContext.java:406)
            at test.ListJNDIBindingsWithClientJars.main(ListJNDIBindingsWithClientJars.java:22)
            Caused by: java.lang.ClassNotFoundException: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory (no security manager: RMI class loader disabled)
            at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:371)
            at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
            at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
            at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
            at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1544)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
            at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
            at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:962)
            ... 3 more

            After adding the sar containing the missing HiLoKeyGeneratorFactory class we get the following error:

            Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/system/ServiceMBeanSupport
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:242)
            at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:154)
            at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
            at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
            at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1544)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
            at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
            at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:962)
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:915)
            at javax.naming.InitialContext.listBindings(InitialContext.java:406)
            at test.ListJNDIBindingsWithClientJars.main(ListJNDIBindingsWithClientJars.java:22)

            After adding the jboss-system.jar containing the ServiceMBeanSupport class we get the following error:

            Exception in thread "main" java.lang.IllegalStateException: No 'jboss' MBeanServer found!
            at org.jboss.mx.util.MBeanServerLocator.locateJBoss(MBeanServerLocator.java:122)
            at org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory.readObject(HiLoKeyGeneratorFactory.java:438)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1809)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
            at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
            at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:962)
            at org.jnp.interfaces.NamingContext.listBindings(NamingContext.java:915)
            at javax.naming.InitialContext.listBindings(InitialContext.java:406)
            at test.ListJNDIBindingsWithClientJars.main(ListJNDIBindingsWithClientJars.java:22)

            public class ListJNDIBindings {
            
             public static void main(String[] args) {
            
             Properties props = new Properties();
             props.put(Context.INITIAL_CONTEXT_FACTORY, org.jnp.interfaces.NamingContextFactory.class.getName());
             props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
             props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            
             try {
             Context context = new InitialContext(props);
             NamingEnumeration<Binding> ne = context.listBindings("");
             while (ne.hasMore()) {
             System.out.println(ne.nextElement());
             }
             } catch (NamingException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
             }
             }
            }
            


            • 3. Re: Standalone client getting errors while attempting to acc
              jaikiran pai Master

               

              "goja" wrote:

              It looks like a JBoss standalone client cannot browse the JNDI binding because of a dependency of the client jars on a sar and jboss-server.jar, which in turns throws an exception complaining about "No 'jboss' MBeanServer found!".

              Any other ideas?


              public class ListJNDIBindings {
              
               public static void main(String[] args) {
              
               Properties props = new Properties();
               props.put(Context.INITIAL_CONTEXT_FACTORY, org.jnp.interfaces.NamingContextFactory.class.getName());
               props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
               props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
              
               try {
               Context context = new InitialContext(props);
               NamingEnumeration<Binding> ne = context.listBindings("");
               while (ne.hasMore()) {
               System.out.println(ne.nextElement());
               }
               } catch (NamingException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               }
               }
              }
              


              Well, if you look at the code that you posted, you are using the listBindings API on the Context, which as per the javadoc:

              Enumerates the names bound in the named context, along with the objects bound to them.


              Any application can bind any object to the JNDI tree and if you use the listBindings API on the client side then effectively you will have to have the class/jar files of those objects on the client side.

              If you want to browse the JNDI tree then you can use the list() API available on the Context as follows:
              
              package org.myapp;
              
              import java.util.Properties;
              
              import javax.naming.Binding;
              import javax.naming.Context;
              import javax.naming.InitialContext;
              import javax.naming.NamingEnumeration;
              import javax.naming.NamingException;
              
              public class ListJNDIBindings {
              
               public static void main(String[] args) {
              
               Properties props = new Properties();
               props.put(Context.INITIAL_CONTEXT_FACTORY, org.jnp.interfaces.NamingContextFactory.class.getName());
               props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
               props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
              
               try {
               Context context = new InitialContext(props);
               NamingEnumeration ne = context.list("");
              
               while (ne.hasMore()) {
               System.out.println(ne.nextElement());
               }
               } catch (NamingException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               }
               }
              }


              The javadoc of the list API mentions:

              Enumerates the names bound in the named context, along with the class names of objects bound to them


              In this case you need not have the jar/class files of the all the objects bound to the JNDI tree. I was able to get this code working by including the jbossall-client.jar file in the client's classpath.