4 Replies Latest reply on Jan 7, 2009 9:13 PM by ezani abdul halim

    Always getting not bound naming exceptions

    ezani abdul halim Newbie

      Hi there

      I am using JBoss 4.2.2.GA, Eclipse Ganymede and OracleXE with JDK5.0_14. I seem to always get "XXX not bound" exceptions for my sample project when I do lookups through the JNDI initial naming context whether it is a datasource in the java namespace or an ejb in the global JNDI namespace. I have checked in jmx-console ViewJNDI routine that the JNDI names exits.

      Snippets of my code initializing JNDI naming are as follows :-

      For datasource naming:

      Properties p = new Properties();
      p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      p.put("java.naming.provider.url", "jnp://localhost:1099");
      p.put("java.naming.factory.url.pkgs", "org.jboss.naming.client");
      
      java.sql.Connection conn;
      InitialContext ic = new InitialContext(p);
      javax.sql.DataSource db = (javax.sql.DataSource) ic.lookup("java:OracleXE1_DS");
      


      And for the session EJB3 lookup:
      Properties p = new Properties();
      p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      p.put("java.naming.provider.url", "jnp://localhost:1099");
      p.put("java.naming.factory.url.pkgs", "org.jboss.naming.client");
      
      InitialContext ctx = new InitialContext(p);
      //BiddingTestBeanRemote bidder = (BiddingTestBeanRemote) ctx.lookup("BiddingTestBean");
      BiddingTestBeanRemote bidder = (BiddingTestBeanRemote) PortableRemoteObject.narrow (ctx.lookup("BiddingTestBean"), BiddingTestBeanRemote.class);
      
      


        • 1. Re: Always getting not bound naming exceptions
          ezani abdul halim Newbie

          It also doesn't work if I use this :

          //BiddingTestBeanRemote bidder = (BiddingTestBeanRemote) ctx.lookup("ejb/BiddingTestBean");
          BiddingTestBeanRemote bidder = (BiddingTestBeanRemote) PortableRemoteObject.narrow (ctx.lookup("ejb/BiddingTestBean"), BiddingTestBeanRemote.class);
          


          or this:
          //BiddingTestBeanRemote bidder = (BiddingTestBeanRemote) ctx.lookup("pc:comp/env/ejb/BiddingTestBean");
          BiddingTestBeanRemote bidder = (BiddingTestBeanRemote) PortableRemoteObject.narrow (ctx.lookup("pc:comp/env/ejb/BiddingTestBean"), BiddingTestBeanRemote.class);
          


          Any idea what possible errors I am making?


          • 2. Re: Always getting not bound naming exceptions
            ezani abdul halim Newbie

            For everyone to share, there is this EXCELLENT blog (Oct 2007) from Jaikiran Pai on initial context JNDI naming convention for JBoss AS and how to name the context properly from the lookup code.

            It certainly helped to solve my problem and I'm sure a lot of yours.

            Here's the link:

            http://jaitechwriteups.blogspot.com/search?updated-min=2007-01-01T00:00:00-08:00&updated-max=2008-01-01T00:00:00-08:00&max-results=3

            One interesting point I noted is that because wrapper datasources are bound using the java: namespace, they cannot be accessed from a standalone Java client because this client runs in a different JVM from the JBoss server.

            So you cannot use :

            InitialContext ic = new InitialContext();
            javax.sql.DataSource db = (javax.sql.DataSource) ic.lookup("java:OracleXE1_DS");
            


            from a standalone client. What should you do to access that datasource ? (i.e. how to transfer the datasource from the java namespace to the glbal jndi namespace) ?

            Many thanks, Jaikiran! :-)[/url]

            • 3. Re: Always getting not bound naming exceptions
              jaikiran pai Master

               

              "ezanih" wrote:

              What should you do to access that datasource ?


              You can set the use-java-context to false in the -ds.xml. See this for details http://www.jboss.org/community/docs/DOC-9880


              P.S: Glad to know the blog helped :)

              • 4. Re: Always getting not bound naming exceptions
                ezani abdul halim Newbie

                Agreed, Jaikiran! Thanks !

                Example code (for everyone) :-

                <datasources>
                 <local-tx-datasource>
                 <jndi-name>OracleXE1_DS</jndi-name>
                 <use-java-context>false</use-java-context>
                 <connection-url>jdbc:oracle:thin:system/system@localhost:1521:XE</connection-url>
                 <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                 <user-name>system</user-name>
                 <password>system</password>
                 <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
                 <metadata>
                 <type-mapping>Oracle10g</type-mapping>
                 </metadata>
                 </local-tx-datasource>
                </datasources>
                


                P.S. This is for oracle-ds.xml for my Oracle DB. Change the paras accordingly for the db you are using. :-)