1 Reply Latest reply on Jul 20, 2002 8:29 AM by kiuma

    What am i doing wrong? (JB3.0/Postgres - DS not bound)

    Stefan Kuehn Newbie

      Hi!

      What am i doing wrong?
      I trying to port an application to JBoss (3.0). and the problem is, that i don't find the Data source (DS) from within my session bean.
      (I can access it using JDBC from the IDE "Forte4Java" using the same URL as in the postgres-service.xml file)

      I have done this:
      1. I put the Postgres JDBC-Driver in the [JB-Inst-Dir]/lib directory
      (I also have tried the [JB-Inst-Dir]/server/default/lib directory ?!?)

      2. I put the postgres-service.xml file in the [JB-Inst-Dir]/server/default/deploy directory
      I gave my DS the JNDI-Name "UKontakt" like this:
      ...
      UKontakt


      <config-property name="ConnectionURL" type="java.lang.String">jdbc:postgresql://192.168.115.7:5432/udb2</config-property>
      <config-property name="DriverClass" type="java.lang.String">org.postgresql.Driver</config-property>
      <config-property name="UserName" type="java.lang.String"></config-property>
      <config-property name="Password" type="java.lang.String"></config-property>


      ...

      3. I put the login-config.xml file in the [JB-Inst-Dir]/server/default/conf directory
      (i also have tried the [JB-Inst-Dir]/server/default/deploy directory ?!?)
      ...
      <application-policy name = "PostgresDbRealm">

      <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
      <module-option name = "principal">nafets</module-option>
      <module-option name = "userName">nafets</module-option>
      <module-option name = "password">nafets</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=PostgresDS</module-option>
      </login-module>

      </application-policy>
      ...

      4. The Session bean deployment descriptor in the file ejb-jar-xml looks like this:
      (I do find the session bean and can execute it calling it from an JSP-page)
      ...

      <ejb-name>LogInEJB</ejb-name>
      ...
      <resource-ref>
      <res-ref-name>jdbc/UKontaktDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>
      ...

      5. I maped the coded name of the DS to the JNDI-name in the jboss.xml like this:
      ...

      <ejb-name>LogInEJB</ejb-name>
      <jndi-name>ejb/Login</jndi-name>
      <resource-ref>
      <res-ref-name>jdbc/UKontaktDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/UKontakt</jndi-name>
      </resource-ref>

      ...

      6. All this is deployed without errors.

      7. When executing this code in the sesson bean, the enumaration has 1 entry.
      The values of the variable are shown in the coments ro the right.
      It seems to me, that if the mapping, coded name -> jndi name is ok!?! (content of variable b)
      for (NamingEnumeration enum2 = jndiContext.listBindings("java:comp/env/jdbc"); enum2.hasMoreElements();) {
      Object o = enum2.nextElement();
      Binding b = (Binding) o; //b = "UKontaktDB:javax.naming.LinkRef:Reference Class Name:javax.naming.LinkRefType: LinkAdressContent:java:/UKontakt"
      String Name = b.getName(); //Name = "UKontaktDB"
      String ClassName = b.getClassName(); //ClassName = "javax.naming.LinkRef"
      Object o2 = b.getObject();
      }

      8. When executing this code direct after the ones in 7. above i get an NameNotFoundException
      Context jdbcContext = (Context) jndiContext.lookup("java:comp/env/jdbc");
      javax.sql.DataSource DBDataSource = (javax.sql.DataSource) jdbcContext.lookup("UKontaktDB");

      9. The message in the excepton says:
      javax.naming.NamaNotFoundException UKontakt not bound

      10. When i start the JBoss Agent View (on Port 8082) the Postgres DS is listed under the
      "jboss.jca" headline.
      When clicking on the entry "service=LocalTxDS, name=PostgresDS" the content of the page
      says that the JndiName for the DS is UKontakt
      Doesn't that mean, that UKontakt IS bound???


      If you can help, i'l try to show my appreciation for the rest of my life :-)

      Rgds
      Stefan