4 Replies Latest reply on Jun 15, 2010 10:44 AM by Anand Krishnan

    $Proxy60 - returned by JBOSS JNDI Context

    Anand Krishnan Newbie

      Hi All,

       

                I am facing a strange ERROR, infact it is not an error thats how
      the jboss returns the object. JBOSS returns $Proxy60, when i try to
      retrieve object from Context. Please find the details below.

       

      MBEAN DEFN:
      <server>
      <mbean code="org.jboss.naming.ExternalContext"

       

      name="jboss.jndi:service=ExternalContext,jndiName=external/ldap/jboss">
          <attribute name="JndiName">java:external/ldap/jboss</attribute>
          <attribute name="Properties">

       

      java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
          </attribute>
          <attribute
      name="InitialContext">javax.naming.ldap.InitialLdapContext</attribute>
          <attribute name="RemoteAccess">false</attribute>
      </mbean>
      </server>

       

      The Mbean is JBOSS Class, I am testing this with JBoss standards and not
      with my customClass.

       

      [step A]Context envContext = (Context)ctx.lookup("java:");
      [step B]Object ldapCtx = (Object)envContext.lookup("jndi/externalLDAP");

       

      In step A, I could retieve the Initial Context.
      But, in step B, It returns me $Proxy60 and I am unable to typecast this
      object.

       

      Here s my code again:

       

      [1]Context ctx = new InitialContext();
      [2]Context envContext = (Context)ctx.lookup("java:");
      [3]Object ldapCtx = (Object)envContext.lookup("jndi/externalLDAP");
      [4]System.out.println("Class name:- "+ldapCtx .getClass().getName());
      [5]System.out.println("Object value:- "+ldapCtx.toString());

       

      The output is as follows
      [line 4: prints this value] Class name:- $Proxy60
      [line 5: prints this value] Object value:-
      javax.naming.InitialContext@b3826f

       

      IF I type caste to InitialContext, it gives me ClassCastException.

       

      Any suggestion, how to use this object?

       

      Thanks,

      Anand

        • 1. Re: $Proxy60 - returned by JBOSS JNDI Context
          Anand Krishnan Newbie

          I had come across the $proxy60, by using Context{line 3}, instead of InitialContext as given below:

           

          /*[1]*/PrintWriter w = response.getWriter();
          /*[2]*/NamingContext envCtx = (NamingContext) intialCtx.lookup("java:");
          /*[3]*/Context ldapCtx = (Context) envCtx.lookup("external/ldap/jboss");
          /*[4]*/InitialContext initialContext = new InitialContext(ldapCtx.getEnvironment());
          /*[5]*/w.println(initialContext.toString()+"<br/>");
          /*[6]*/w.println(initialContext.getEnvironment());

           


          {line 5 prints :}
          javax.naming.InitialContext@1cece51
          {line 6 prints :}
          {java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces}

           


          I need to convert this object to LocalOnlyContextFactory, thats how I could use in my application.
          Please suggest!

           

          If try type-casting, it gives ClassCastException:
          LocalOnlyContextFactory typeCtx =(LocalOnlyContextFactory)ldapctx;{ldapCtx from line:3}

           

          Please suggest solution to get the right context to use in my application.

           

          Thanks,

          Anand

          • 2. Re: $Proxy60 - returned by JBOSS JNDI Context
            Anand Krishnan Newbie
             I had attached the sample application, and had commented on JNDITest Servlet source code. Please check and revert.

             

             

            Output Screen:

            ~~~~~~~~~~~~~~~~~~~~~~~~///////////////~~~~~~~~~~~~~~~~~~~~~~~
            ~~~~~~~~~~~~~~~~~~~~~~~~///////////////~~~~~~~~~~~~~~~~~~~~~~~

            org.jnp.interfaces.NamingContext
            org.jnp.interfaces.NamingContext@11c5342
            {jnp.parsedName=, java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces}javax.naming.InitialContext@131a24c
            $Proxy71
            {java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces}

            Typecasting
            javax.naming.InitialContext@9e3fc2
            {java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces}

            ~~~~~~~~~~~~~~~~~~~~~~~~///////////////~~~~~~~~~~~~~~~~~~~~~~~
            ~~~~~~~~~~~~~~~~~~~~~~~~///////////////~~~~~~~~~~~~~~~~~~~~~~~


            Hope, Someone there to help me...

             

            Thanks,

            Anandhakrishnan

            • 3. Re: $Proxy60 - returned by JBOSS JNDI Context
              jaikiran pai Master

              Are you packaging any jar files containing org.jboss.naming.* or org.jnp.* packages in your application? If yes, then remove such jars from your application packaging.

              • 4. Re: $Proxy60 - returned by JBOSS JNDI Context
                Anand Krishnan Newbie

                Hi,

                 

                Thanks for your information,

                 

                I don't have any single jar in my war file, All the required class are available by default in Jboss 4.2.3 GA version.

                 

                I got some these input from others discussion.

                 

                Thanks,

                Anand