1 Reply Latest reply on Jun 24, 2002 11:19 AM by Chris McCafferty

    JBoss/JNDI Question.

    Shailesh Dangi Newbie

      Guys:

      I have a little trouble understanding how the objects are bound and discovered with JNDI in Jboss. Do I specify the JNDI Binding in Jboss.xml file? Does Jboss follow the standard J2EE Naming Conventions to find objects relative to java:comp/env.? Even though I have specified
      <jndi-name>interest/Interest</jndi-name> the jboss.xml file why is the object (proxy)
      bound against “Interest” name under the root context?

      More over I am not able to find resources if I use java:comp/env/jdbc/OraclePoolDS to get Connection objects. This happens no matter what I user “jdbc/OraclePoolDS” or just “OraclePoolDS” or even “java:/jdbc/OracleDBPool”. The built in “java:/DefaultDS” also doesn’t work. Could some one spend some time explaining how to do the bindings?


      Secondly, as part of Bean-Container contract, the container provider is mandated to implement enterprise bean's home and component interfaces. Where does JBoss generate and store these implementations?.

      I also have a test JNDI program (see below) that looks up jndi.properties from the classpath.
      I am printing the env variables and the all the objects bound. There is nothing bound under
      “java:”. Weird.

      Please help !!!


      [INFO,HypersonicDatabase] Database started
      [INFO,HypersonicDatabase] Started
      [INFO,DefaultDS] Starting
      [INFO,DefaultDS] XA Connection pool DefaultDS bound to java:/DefaultDS
      [INFO,DefaultDS] Started
      [INFO,jdbc/OracleDBPool] Starting
      [INFO,jdbc/OracleDBPool] XA Connection pool jdbc/OracleDBPool bound to java:/jdbc/OracleDBPool
      [INFO,jdbc/OracleDBPool] Started
      .
      .
      .
      ******************************************************************************************
      Sample JNDI Program

      package com.companyname.utils;

      import javax.naming.*;
      import java.util.*;

      public class TestJNDI extends Object {

      /**
      * Constructor
      */
      public TestJNDI() {

      }

      public static void main(String [] args) throws Exception{
      InitialContext jndiContext = new InitialContext();
      Hashtable env = jndiContext.getEnvironment();
      System.out.println("*****************************************");
      for(Enumeration enum = env.keys();enum.hasMoreElements();){
      String key = enum.nextElement().toString();
      System.out.println(key+"="+env.get(key).toString());
      }
      System.out.println("*****************************************");
      NamingEnumeration enum = jndiContext.list("");
      while (enum.hasMore()) {
      System.out.println(enum.next());
      }

      System.out.println("*****************************************");
      enum = jndiContext.list("java:/");
      while (enum.hasMore()) {
      System.out.println(enum.next()); ß This is empty
      }
      System.out.println("*****************************************");

      Object ref = jndiContext.lookup("Interest"); //From example – shouldn’t this be java:comp/env/ejb/
      System.out.println(ref.getClass().getName());
      System.out.println("*****************************************");


      System.out.println("*****************************************");

      ref = jndiContext.lookup("java:/DefaultDS”);//From example throws Exception
      System.out.println(ref.getClass().getName());
      System.out.println("*****************************************");

      jndiContext.close();
      }
      }


      ******************************************************************************************
      Sample JNDI Output

      ******************************************************************************************
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=NY500-03-164A.bloomberg.com:1099
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      ******************************************************************************************
      TopicConnectionFactory: javax.naming.LinkRef
      jmx: org.jboss.jmx.server.JMXAdaptorImpl
      ConnectionFactory: org.jboss.mq.SpyConnectionFactory
      UserTransactionSessionFactory: org.jboss.tm.usertx.server.UserTransactionSessionFactoryImpl
      Interest: $Proxy2
      jmx:ny500-03-164a:rmi: org.jboss.jmx.server.RMIConnectorImpl
      XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      invokers: org.jnp.interfaces.NamingContext
      UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
      UILXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      RMIXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      queue: org.jnp.interfaces.NamingContext
      topic: org.jnp.interfaces.NamingContext
      FwkTab: $Proxy4
      UILConnectionFactory: org.jboss.mq.SpyConnectionFactory
      servercollector: org.jboss.management.ServerDataCollector
      RMIConnectionFactory: org.jboss.mq.SpyConnectionFactory
      QueueConnectionFactory: javax.naming.LinkRef
      ******************************************************************************************
      ******************************************************************************************
      $Proxy0
      ******************************************************************************************
      ******************************************************************************************
      javax.naming.NameNotFoundException: DefaultDS not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
      at javax.naming.InitialContext.lookup(InitialContext.java:350)
      at com.companyname.utils.TestJNDI.main(TestJNDI.java:50)


      JBOSS.XML

      <?xml version="1.0" encoding="UTF-8"?>

      <enterprise-beans>

      <ejb-name>Interest</ejb-name>
      <jndi-name>interest/Interest</jndi-name>


      <ejb-name>FwkTab</ejb-name>
      <jndi-name>portal/FwkTab</jndi-name>
      <resource-ref>
      <res-ref-name>jdbc/OracleDBPool</res-ref-name>
      <jndi-name>java:/OracleDBPool</jndi-name> <- Not sure.
      </resource-ref>

      </enterprise-beans>
      <resource-managers>
      <resource-manager res-class="org.jboss.jdbc.XADataSourceLoader">
      <res-name>jdbc/OracleDBPool</res-name>
      <res-jndi-name>java:/OracleDBPool</res-jndi-name>
      </resource-manager>
      </resource-managers>



      EJB-JAR.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar>
      Portal Application
      <display-name>Portal EJB</display-name>
      <enterprise-beans>

      <ejb-name>Interest</ejb-name>
      com.companyname.ejbs.sessionbeans.InterestHome
      com.companyname.ejbs.sessionbeans.Interest
      <ejb-class>com.companyname.ejbs.sessionbeans.InterestBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>
      <resource-ref>
      Oracle DS
      <res-ref-name>jdbc/OracleDBPool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>



      FwkTab
      <ejb-name>FwkTab</ejb-name>
      com.companyname.ejbs.entitybeans.FwkTabHome
      com.companyname.ejbs.entitybeans.FwkTab
      <ejb-class>com.companyname.ejbs.entitybeans.FwkTabBean</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <resource-ref>
      Oracle DS
      <res-ref-name>jdbc/OracleDBPool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      </enterprise-beans>
      </ejb-jar>


      Section of jboss.jcml


      <!-- ==================================================================== -->
      <!-- JDBC -->
      <!-- ==================================================================== -->


      oracle.jdbc.driver.OracleDriver,org.hsqldb.jdbcDriver




      1476
      true
      default
      false



      DefaultDS
      org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl

      jdbc:hsqldb:hsql://localhost:1476
      1200000
      sa
      10

      false
      false
      false
      true
      120000
      1800000
      false
      false
      1.0
      0




      oracle.jdbc.driver.OracleDriver,org.hsqldb.jdbcDriver



      org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl
      jdbc/OracleDBPool
      jdbc:oracle:thin:@crmdev:1521:blpt

      apps
      apps
      2
      2
      true
      20
      20
      false
      false
      true
      false
      false
      1800000
      1.0




      Section of Output from: http://ny500-03-164a.bloomberg.com:8082

      DefaultDomain
      .
      .
      service=XADataSource,name=DefaultDS
      service=XADataSource,name=jdbc/OracleDBPool
      type=Shutdown
      .
      .

      Management
      jndiName=FwkTab
      jndiName=Interest

        • 1. Re: JBoss/JNDI Question.
          Chris McCafferty Newbie

          > I also have a test JNDI program (see below) that looks up jndi.properties from the classpath.
          > I am printing the env variables and the all the objects bound. There is nothing bound under ?java:?. Weird.

          I'm no expert on JNDI and I share much of your confusion. But I have gleaned that anything under the "java" namespace is only accessible to objects within the container, not client programs. So Beans inside your container should be able to look up objects under "java". These name bindings are not apparent to client programs run in processes outside the container.