4 Replies Latest reply on Aug 29, 2006 10:39 AM by wfe wfe

    JNDI datasource not available in one webapp while its availa

    wfe wfe Newbie

      Hi,
      I have a datasource configured using myds-ds.xml in jboss and when starting up it gets bound.

      15:57:43,414 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:name=MyDS,service=DataSourceBinding' to JNDI name 'java:MyDS'

      But I'm not able to access this datasource through the usual context lookup
      InitialContext ctxt = new InitialContext();
      Object o = ctxt.lookup("java:/OracleDS");
      DataSource ds = (DataSource) PortableRemoteObject.narrow(o, DataSource.class);

      I get the following exception.
      javax.naming.NameNotFoundException: OracleDS not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:347)
       at org.foo.bar.db.DataSourceAccess.retrieveDataSource(DataSourceAccess.java:143)


      But, just to test out I created another test webapp and tried to get the datasource in a simple JSP page using the same code. It worked. What did I do wrong. I even tried adding resource-ref, resource-env-ref entries to my web.xml. I'm stumped.


      Heres my datasource config file
      myds-ds.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       <local-tx-datasource>
       <jndi-name>MyDS</jndi-name>
       <connection-url>jdbc:oracle:thin:@oradev:1521:dev</connection-url>
       <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
       <user-name>dev</user-name>
       <password>dev</password>
       <exception-sorter-class-name>
       org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
       </exception-sorter-class-name>
       <min-pool-size>10</min-pool-size>
       <max-pool-size>50</max-pool-size>
       <idle-timeout-minutes>10</idle-timeout-minutes>
       <track-statements>true</track-statements>
       <metadata>
       <type-mapping>Oracle10g</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>
      



        • 1. Re: JNDI datasource not available in one webapp while its av
          jaikiran pai Master

           

          javax.naming.NameNotFoundException: OracleDS not bound

          <jndi-name>MyDS</jndi-name>


          Your lookup code should be:
          Object o = ctxt.lookup("java:/MyDS");


          • 2. Re: JNDI datasource not available in one webapp while its av
            wfe wfe Newbie

            sorry I had been trying to get the datasource using both OracleDS and was checking with MyDS and hence got the the code and stacktrace mixed up here's how its gotta look

            15:57:43,414 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:name=MyDS,service=DataSourceBinding' to JNDI name 'java:MyDS'


            InitialContext ctxt = new InitialContext();
            Object o = ctxt.lookup("java:/MyDS");
            DataSource ds = (DataSource) PortableRemoteObject.narrow(o, DataSource.class);


            javax.naming.NameNotFoundException: MyDS not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
             at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
             at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
             at javax.naming.InitialContext.lookup(InitialContext.java:347)
             at org.foo.bar.db.DataSourceAccess.retrieveDataSource(DataSourceAccess.java:143)


            myds-ds.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <datasources>
             <local-tx-datasource>
             <jndi-name>MyDS</jndi-name>
             <connection-url>jdbc:oracle:thin:@oradev:1521:dev</connection-url>
             <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
             <user-name>dev</user-name>
             <password>dev</password>
             <exception-sorter-class-name>
             org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
             </exception-sorter-class-name>
             <min-pool-size>10</min-pool-size>
             <max-pool-size>50</max-pool-size>
             <idle-timeout-minutes>10</idle-timeout-minutes>
             <track-statements>true</track-statements>
             <metadata>
             <type-mapping>Oracle10g</type-mapping>
             </metadata>
             </local-tx-datasource>
            </datasources>
            


            thanks jaikiran for pointing that out but, I assure you its certainly not because of using mixed up names

            • 3. Re: JNDI datasource not available in one webapp while its av
              wfe wfe Newbie

              More info:
              I think the problem may be because my webapp is not getting bound to the 'java:' namespace because using the dumpContextList method someone posted in this forum I'm able to look at what the context contains.

              Making successive calls of

              System.out.println("Dumping context list for 'java:'");
              dumpContextList(ctxt, "java:");
              System.out.println("Dumping context list for ''");
              dumpContextList(ctxt, "");


              results in
              Dumping context list for 'java:'
              Dumping context list for ''
              1. TopicConnectionFactory: org.jboss.naming.LinkRefPair
              2. UIL2ConnectionFactory: javax.naming.LinkRef
              3. UserTransactionSessionFactory: $Proxy12
              4. UIL2XAConnectionFactory: javax.naming.LinkRef
              5. QueueConnectionFactory: org.jboss.naming.LinkRefPair
              6. UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
              7. jmx: org.jnp.interfaces.NamingContext
              8. UILXAConnectionFactory: javax.naming.LinkRef
              9. UILConnectionFactory: javax.naming.LinkRef


              but from my other webapp i'm getting this for the same piece of code
              Dumping context list for 'java:'
              1. SecurityProxyFactory: org.jboss.security.SubjectSecurityProxyFactory
              2. MyDS: org.jboss.resource.adapter.jdbc.WrapperDataSource
              3. DefaultJMSProvider: org.jboss.jms.jndi.JNDIProviderAdapter
              4. comp: javax.naming.Context
              5. JmsXA: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl
              6. jaas: javax.naming.Context
              7. timedCacheFactory: javax.naming.Context
              8. TransactionPropagationContextExporter: org.jboss.tm.TransactionPropagationContextFactory
              9. StdJMSPool: org.jboss.jms.asf.StdServerSessionPoolFactory
              10. TransactionPropagationContextImporter: org.jboss.tm.TransactionPropagationContextImporter
              11. TransactionManager: org.jboss.tm.TxManager
              Dumping context list for ''
              1. TopicConnectionFactory: org.jboss.naming.LinkRefPair
              2. UIL2ConnectionFactory: javax.naming.LinkRef
              3. UserTransactionSessionFactory: $Proxy12
              4. UIL2XAConnectionFactory: javax.naming.LinkRef
              5. QueueConnectionFactory: org.jboss.naming.LinkRefPair
              6. UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
              7. jmx: org.jnp.interfaces.NamingContext
              8. UILXAConnectionFactory: javax.naming.LinkRef
              9. UILConnectionFactory: javax.naming.LinkRef


              How do i solve this?

              private static void dumpContextList(InitialContext ctx, String prefix) {
               try {
               int i = 1;
               for( Enumeration e = ctx.list( prefix ); e.hasMoreElements(); ) {
               Object o = e.nextElement();
               if ( o instanceof NameClassPair ) {
               System.out.println(i + ". " + o);
               } else {
               System.out.println(i + ". Found object of Class " + o.getClass().getName() + " = \"" + o.toString() + "\"" );
               }
               i++;
               }
               } catch (NamingException e) {
               e.printStackTrace();
               }
              }




              • 4. Re: JNDI datasource not available in one webapp while its av
                wfe wfe Newbie

                I found the problem :D. My build was copying all the jars used for compiling the webapp into the webapp/WEB-INF/lib folder thus putting jboss-*.jar files there. Once I removed them from there, IT WORKS :D