5 Replies Latest reply on Mar 1, 2005 6:36 AM by f94-mgi

    Lookup datasource from client application problem

    f94-mgi

      Gaah! I'm tearing my hair turning bold... :-[ please help!

      I have read documentation and searched this forum and the rest of the 'net ... have found some help but never really the same scenario as mine. I'm stuck!

      This is the case: I wan't to do a lookup for a datasource registered in my JBoss AS. I have created a EAR with a JAR in it, representing the server component of my client application. The thing is I don't have anything in it but the META-INF/application-client.xml and jboss-client.xml. In all examples I have seen the lookup is for an EJB, not a datasource... is it not possible?

      Anyway, this is my code:

      mysql-ds.xml

      <datasources>
       <local-tx-datasource>
       <jndi-name>jdbc/WpDB</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/wp</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>wpuser</user-name>
       <password>wp</password>
       </local-tx-datasource>
      </datasources>


      application.xml
      <application>
       <display-name>WP</display-name>
       <description />
       <module>
       <java>client.jar</java>
       </module>
      </application>


      application-client.xml
      <application-client ...>
       <display-name>WP client</display-name>
       <resource-ref>
       <res-ref-name>jdbc/WpDB</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       </resource-ref>
      </application-client>


      jboss-client.xml:
      <jboss-client>
       <jndi-name>wp-client</jndi-name>
       <resource-ref>
       <res-ref-name>jdbc/WpDB</res-ref-name>
       <jndi-name>java:jdbc/WpDB</jndi-name>
       </resource-ref>
      </jboss-client>


      When I start JBoss AS I get the following about my bound datasource:
      16:06:19,734 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=jdbc/WpDB,service=DataSourceBinding to JNDI name 'java:jdbc/WpDB'


      I start my client with the following command:
      java -cp .;./lib/jbossall-client.jar -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099 -Djava.naming.factory.url.pkgs=org.jboss.naming.client -Dj2ee.clientName=wp-client wp.client.Main


      I get the following exception:
      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NamingException: Name not found java:jdbc/WpDB]


      If I change the inner "jndi-name" in my jboss-client.xml to for example "hey baberiba" I would get the exception "... Name not found hey baberiba" so this is where the error lays.
      If I check in the JMX web I can see this about the datasource:
      JndiName: jdbc/WpDB
      BindName: java:jdbc/WpDB

      Someone have a clue?

        • 1. Re: Lookup datasource from client application problem
          f94-mgi

          OK, I might add one thing.

          In the same EAR as my JAR is placed, I have a WAR with a web application in it. I use my datasource in this web application and it works fine!

          jboss-web.xml

          <jboss-web>
           <resource-ref>
           <res-ref-name>jdbc/WpDB</res-ref-name>
           <jndi-name>java:jdbc/WpDB</jndi-name>
           </resource-ref>
          </jboss-web>


          I think that this is completely transparent to the client application, but still it does not work in the client application case... any suggestions please?

          • 2. Re: Lookup datasource from client application problem
            stevenpeh

            couple points to note.

            1. Lookup of objects bound to the JNDI tree using java:/ prefix will most likely not work if the lookup code resides outside of the App server.

            2. As some of the wise folk here pointed out to me when i went thru a similar situation as you, looking up datasources from stand alone clients will only work for jboss 4.0

            This would suggest you work your way up from point 2. Cheers. ;-)

            • 3. Re: Lookup datasource from client application problem
              f94-mgi

              Thank you stevenpeh for your reply!

              As answer to your points:

              1. The thing is that the lookup seems to work... it is the "dereferencing" inside JBoss that fails. I have tried to change the jboss-client.xml to for example:

              <jboss-client>
               <jndi-name>wp-client</jndi-name>
               <resource-ref>
               <res-ref-name>test</res-ref-name>
               <jndi-name>heybaberiba</jndi-name>
               </resource-ref>
              </jboss-client>

              (and the application-client.xml is also changed to contain the res-ref-name test)
              and if I do a lookup on the name "java:comp/env/test" I get the error "could not dereference object [Root exception is javax.naming.NameNotFoundException: heybaberiba not bound]". Obviously I have no name heybaberiba bound so this should be correct. The thing is java:jdbc/WpDB does not work either, and if I try only jdbc/WpDB I get "could not dereference object [Root exception is javax.naming.NameNotFoundException: jdbc not bound]"... so I figure either my inner jndi-name in the jboss-client.xml is wrong or my datasource is not bound correctly - but it works in the web-scenario, and here I use java:jdbc/webping in the jboss-web.xml. Hmmm... anyone still following me?

              2. I use JBoss 4 so that should be OK. Nice to hear that it should work :)

              Cheers to you too stevenpeh ;)

              • 4. Re: Lookup datasource from client application problem
                stevenpeh

                in your mysql-ds.xml file add this line after your jndi-name

                <use-java-context>false</use-java-context>
                


                now you should be able to lookup the datasource from a stand alone client using whatever jndi name you set in the mysql-ds.xml... no need for any java:/ prefix. Also make sure you have the necessary jboss*.jar in your client classpath.

                Cheers.

                • 5. Re: Lookup datasource from client application problem
                  f94-mgi

                  Yeeeeeehaaaaaaa! It works!!!! :-D

                  Thank you thank you thank you...!!!!

                  ... But I'm not sure what I've done and why it didn't work earlier... is this an ugly solution?

                  I own you stevenpeh