2 Replies Latest reply on May 10, 2006 10:32 AM by anthony dorado

    [JNDI] NameNotFoundException: Database not bound

    anthony dorado Newbie

      Hello everybody.

      I can't find the solution of this problem on the web even if I saw many similar problems.

      First. I had problem using DatabaseServerLoginModule... with this error :

      javax.security.auth.login.LoginException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:133) at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:182)


      I debuged it ... and found that the error is raised here :
      /****** In jboss databaseserverloginmodule file ***** /
       protected String getUsersPassword() throws LoginException
       { String username = getUsername();
       String password = null;
       Connection conn = null;
       PreparedStatement ps = null;
       try
       { InitialContext ctx = new InitialContext();
       DataSource ds = (DataSource) ctx.lookup(dsJndiName);
       .....
      


      The InitialContext() works well.

      but the ctx.lookup(dsJndiName) raises the error.


      So I tryed this easy code :

       Properties props = new Properties();
       props.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       props.put(Context.URL_PKG_PREFIXES,
       "org.jboss.naming:org.jnp.interfaces");
       InitialContext ctx = null;
       try {
       ctx = new InitialContext(props);
       } catch (NamingException ex2) {
       System.out.print("Error while InitialContext");
       }
       DataSource ds = null;
       try {
       ds = (DataSource) ctx.lookup("java:TestDataSource");
       } catch (NamingException ex3) {
       System.out.println("Error while LOOKUP");
       ex3.printStackTrace();
       }
      


      here is the message error :
      Error while LOOKUP
      javax.naming.NameNotFoundException: TestDataSource 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 sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
      ...



      My configuration :

      =========================================================================
      
       JBoss Bootstrap Environment
      
       JBOSS_HOME: /usr/local/jboss-4.0.3SP1
      
       JAVA: /usr/java/jdk1.5.0_06//bin/java
      
       JAVA_OPTS: -server -Xms128m -Xmx128m -Dprogram.name=run.sh
      
       CLASSPATH: /usr/local/jboss-4.0.3SP1/bin/run.jar:/usr/java/jdk1.5.0_06//lib/tools.jar
      
      =========================================================================
      
      11:29:26,115 INFO [Server] Starting JBoss (MX MicroKernel)...
      11:29:26,123 INFO [Server] Release ID: JBoss [Zion] 4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231751)
      11:29:26,127 INFO [Server] Home Dir: /usr/local/jboss-4.0.3SP1
      11:29:26,128 INFO [Server] Home URL: file:/usr/local/jboss-4.0.3SP1/
      11:29:26,131 INFO [Server] Patch URL: null
      11:29:26,131 INFO [Server] Server Name: default
      11:29:26,132 INFO [Server] Server Home Dir: /usr/local/jboss-4.0.3SP1/server/default
      11:29:26,133 INFO [Server] Server Home URL: file:/usr/local/jboss-4.0.3SP1/server/default/
      11:29:26,134 INFO [Server] Server Temp Dir: /usr/local/jboss-4.0.3SP1/server/default/tmp
      11:29:26,285 INFO [Server] Root Deployment Filename: jboss-service.xml
      11:29:27,140 INFO [ServerInfo] Java version: 1.5.0_06,Sun Microsystems Inc.
      11:29:27,140 INFO [ServerInfo] Java VM: Java HotSpot(TM) 64-Bit Server VM 1.5.0_06-b05,Sun Microsystems Inc.
      11:29:27,141 INFO [ServerInfo] OS-System: Linux 2.6.12-12mdk,amd64


      test-ds.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       <local-tx-datasource>
       <jndi-name>TestDataSource</jndi-name>
       <connection-url>jdbc:mysql://localhost/test</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password>root</password>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
      </local-tx-datasource>
      </datasources>
      


      jndi.properties
      in path : /usr/local/jboss-4.0.3SP1/server/default/conf
      and also in : /usr/java/jdk1.5.0_06/lib/security

      # DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
      #
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=jnp://localhost:1099
      


      When I start Jboss :
      11:31:05,661 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=TestDataSource' to JNDI name 'java:TestDataSource'
      



      I tryed :
      ds = (DataSource) ctx.lookup("java:TestDataSource");
      ds = (DataSource) ctx.lookup("TestDataSource");
      ds = (DataSource) ctx.lookup("java:/TestDataSource");
      ds = (DataSource) ctx.lookup("java:java:TestDataSource"); // why not :p

      Nothing works, same error
      Maybe I forgot a little thing... I hope someone knows what I forgot.


      Let me know if you need more details.
      Thank you very much for your help

      (sorry for my english)