6 Replies Latest reply on Apr 5, 2011 7:30 AM by jaikiran

    JNDI Standalone client

    ajitsaha67

      I have tested the Standard MBean example program from JBoss site. It is working fine and accessible from same VM. I mean to say when I accessing from jsp by using following code then it works file

       

      InitialContext init=new InitialContext();

       

      HashMap map=(HashMap) init.lookup("inmemory/map/TestMap");

       

       

       

      But when I am accessing from Stanalone client then it return null. Please help me.

        • 1. JNDI Standalone client
          wolfgangknauf

          Hi,

           

          for a standalone client, you have to provide a configuration for the InitialContext:

           

                  Properties props = new Properties();

                  props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                  props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");

                  props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");

                 

                  InitialContext initialContext = new InitialContext(props);

           

          Do you want to perform a lookup in global JNDI or do you lookup something in your "Environment naming context"?

           

          Best regards

           

          Wolfgang

          • 2. JNDI Standalone client
            ajitsaha67

            In JBoss Community documentation, I have tested

            3.4.3.1. A Standard MBean Example program it is working absolutely fine. The access code of HashMap is perfectly working. But when I am trying to access from outside JBoss, it returns null obviously I have set the environment property in following way

             

                  Properties prop=new Properties();

                  prop.setProperty(Context................. the way you have mensioned on previous reply.

             

            But still it gives null value. It is not returing HashMap value.

            • 3. JNDI Standalone client
              jaikiran

              I guess the HashMap content isn't serializable.

              • 4. JNDI Standalone client
                ajitsaha67

                This HashMap object I am getting in jsp program

                 

                But I am not getting in Standalone client. HashMap is Serializable object.

                 

                Shall I give you complete code, so that you can help me.

                • 5. JNDI Standalone client
                  wolfgangknauf

                  Hi,

                   

                  I took a look at the sample at http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/Writing_JBoss_MBean_Services-A_Standard_MBean_Example.html

                  It uses the "NonSerializableFactory": http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/naming/NonSerializableFactory.java.html

                   

                  The JavaDoc of this class states:

                   

                  A utility class that allows one to bind a non-serializable object into a
                  local JNDI context. The binding will only be valid for the lifetime of the
                  VM in which the JNDI InitialContext lives
                  A utility class that allows one to bind a non-serializable object into a local JNDI context. The binding will only be valid for the lifetime of the VM in which the JNDI InitialContext lives

                  "A utility class that allows one to bind a non-serializable object into a local JNDI context. The binding will only be valid for the lifetime of the VM in which the JNDI InitialContext lives"

                   

                  To my understanding, this means that you can lookup the bound data only if your process is in the same VM. But a standalone client will not be able to see it.

                   

                  There is a class "Util", which has a bunch of methods to work with JNDI bindings ( http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/naming/Util.java.html ) - maybe they allow binding to non-local VM, but I don't know this much about JNDI internal to provide further help.

                   

                  Best regards

                   

                  Wolfgang

                  • 6. JNDI Standalone client
                    jaikiran

                    Wolfgang Knauf wrote:

                     

                    I took a look at the sample at http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/Writing_JBoss_MBean_Services-A_Standard_MBean_Example.html

                    It uses the "NonSerializableFactory": http://docs.jboss.org/jbossas/javadoc/4.0.2/org/jboss/naming/NonSerializableFactory.java.html

                     

                    The JavaDoc of this class states:

                     

                    A utility class that allows one to bind a non-serializable object into a
                    #local JNDI context. The binding will only be valid for the lifetime of the
                    #VM in which the JNDI InitialContext lives
                    A utility class that allows one to bind a non-serializable object into a #local JNDI context. The binding will only be valid for the lifetime of the #VM in which the JNDI InitialContext lives

                    "A utility class that allows one to bind a non-serializable object into a local JNDI context. The binding will only be valid for the lifetime of the VM in which the JNDI InitialContext lives"

                     

                    To my understanding, this means that you can lookup the bound data only if your process is in the same VM. But a standalone client will not be able to see it.

                    That's correct!