2 Replies Latest reply on Dec 5, 2015 2:38 PM by George Berish

    Why does JNDI Queue lookup work but DataSource lookup fail?

    George Berish Novice

      I created a Queue and a DataSource with what I thought were identically structured JNDI names.  But while my client can lookup the Queue, it fails when trying to lookup the DataSource.  Can anyone tell me what I'm doing wrong?  (If anyone knows how to stop the unrequested output to my Console (indented red lines in console, I'd appreciate it.)

       

      I pasted the following below:

      A.  Client Code

      B.  standalone-full.xml excerpts for the Queue and DataSource

      C.  Client's Eclipse Console Output

      D.  WildFly server.log lines that seem to apply

       

      Notes:  I just typed in the xml for the Queue.

      I used the CLI to create the mysql driver.

      I let the admin console set up the DataSource in standalone-full.xml.

      The admin console says it connects successfully.

      Running WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final)

       

      A.  Client Code

      package org.america3.gotest.database;

      import java.util.Properties;

      import javax.jms.Queue;

      import javax.naming.CommunicationException;

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.sql.DataSource;

       

      public class TestMysqlDataSource {

        /**

         * these are the properties required to secure an

         * InitialContext() from WIldFly by a standalone Java Client

         */

        static final private Properties ENV = new Properties() {

          private static final long serialVersionUID = 1L;

          {

            put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 

            put(Context.PROVIDER_URL, "http-remoting://localhost:8080");

            put(Context.SECURITY_PRINCIPAL, "jmsuser"); 

            put(Context.SECURITY_CREDENTIALS, "jmsuser@123"); 

            put("jboss.naming.client.ejb.context", true); 

          }

        };

        // class members

        private Context    ctx           = null;

       

        // constructor

        private TestMysqlDataSource () {

          System.out.println(" constructor() :  begin");

          try {

            ctx = new InitialContext(ENV);

            System.out.println(" constructor() :  InitialContext lookup successful");

            System.out.println(" constructor() :  " + ctx);

            // test ctx instance by looking up a known Queue

            Queue jmsSendToQueue = (Queue) ctx.lookup("jms/goSvrReceiveQueue");

            System.out.println(" constructor() :  Queue lookup succeeded");

            System.out.println(" constructor() :  " + jmsSendToQueue.getQueueName());

            System.out.println(" constructor() :  end");

         

          } catch (CommunicationException e) {

            System.out.println(" constructor() :  You forgot to start WildFly dummy!");

            System.out.println(" constructor() :  end");

          } catch (Exception e) {

            System.out.println(" constructor() :  caught :  " + e.getClass().getName());

            System.out.println("                     message:  " + e.getMessage());

            System.out.println(" constructor() :  end");

            System.out.println(" constructor() :  STACK TRACE\n");

            e.printStackTrace();

          }

        }

       

        static public void main (String[] args){

          System.out.println("main() : begin");

          TestMysqlDataSource test = new TestMysqlDataSource();

          try {

         

            System.out.println(" main() :  looking up DataSource");

            DataSource ds = (DataSource) test.ctx.lookup("jdbc/tappds");

            System.out.println(" main() :  DataSource lookup successful");

            System.out.println(" main() :  " + ds.getClass().getName());

            System.out.println("main() : end");

         

          } catch (Exception e) {

            System.out.println(" main() :  caught :  " + e.getClass().getName());

            System.out.println(" main() :  message:  " + e.getMessage());

            System.out.println("main() : end");

            System.out.println("STACK TRACE");

            try {

              /*

               * this prevent e.printstack() from starting on System.err before all

               * System.out lines above are printed.

               */

              Thread.sleep(500);

            } catch (InterruptedException e1) {

              e1.printStackTrace();

            }

            e.printStackTrace();

          }

        } 

      }

       

      B.  standalone-full.xml excerpts

      For Queue:

      <subsystem xmlns="urn:jboss:domain:messaging:3.0">

        ....

        <hornetq-server>

          ...

          <jms-destinations>

            ...

            <jms-queue name="goSvrSendQueue">

              <entry name="java:jboss/exported/jms/goSvrSendQueue"/>

              <durable>true</durable>

            </jms-queue>

          </hornetq-server>

      </subsystem>


      For DataSource:

      <subsystem xmlns="urn:jboss:domain:datasources:3.0">

        <datasources>

        ...

          <datasource jta="true" jndi-name="java:jboss/exported/jdbc/tappds" pool-name="TappDS" enabled="true" use-ccm="true">

            <connection-url>

              jdbc:mysql://localhost:3306/tappdb

            </connection-url>

            <driver-class>

              com.mysql.jdbc.Driver

            </driver-class>

            <driver>mysql</driver>

            <security>

              <user-name>tappdbUser</user-name>

              <password>&amp;MxTappOTB&amp;</password>

            </security>

            <validation>

              <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>

              <background-validation>

                true

              </background-validation>

              <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>

            </validation>

          </datasource>

           ...

          <drivers>

            <driver name="mysql" module="com.mysql.driver">

              <driver-class>com.mysql.jdbc.Driver</driver-class>

            </driver>

          </drivers>

        </datasources>

      </subsystem>

       

      C. Client's Eclipse Console Output

      main() :  begin

        constructor() :  begin

      Dec 04, 2015 2:07:01 PM org.xnio.Xnio <clinit>

      INFO: XNIO version 3.3.1.Final

      Dec 04, 2015 2:07:01 PM org.xnio.nio.NioXnio <clinit>

      INFO: XNIO NIO Implementation Version 3.3.1.Final

      Dec 04, 2015 2:07:01 PM org.jboss.remoting3.EndpointImpl <clinit>

      INFO: JBoss Remoting version 4.0.9.Final

          constructor() :  InitialContext lookup successful

          constructor() :  javax.naming.InitialContext@10d59286

      Dec 04, 2015 2:07:02 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

      INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]

      Dec 04, 2015 2:07:02 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

      INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@4de5031f, receiver=Remoting connection EJB receiver [connection=Remoting connection <642f3fe>,channel=jboss.ejb,nodename=ace]} on channel Channel ID a2f7b517 (outbound) of Remoting connection 5af97850 to localhost/127.0.0.1:8080

      Dec 04, 2015 2:07:02 PM org.jboss.ejb.client.EJBClient <clinit>

      INFO: JBoss EJB Client version 2.1.1.Final  

          constructor() :  Queue lookup succeeded

          constructor() :  goSvrReceiveQueue

        constructor() :  end

        main() : looking up DataSource

      Dec 04, 2015 2:07:02 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient

      INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.

      Dec 04, 2015 2:07:02 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleEnd

      INFO: EJBCLIENT000016: Channel Channel ID a2f7b517 (outbound) of Remoting connection 5af97850 to localhost/127.0.0.1:8080 can no longer process messages

      Dec 04, 2015 2:07:02 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

      INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]

      Dec 04, 2015 2:07:02 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

      INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@4de5031f, receiver=Remoting connection EJB receiver [connection=Remoting connection <3b54d70a>,channel=jboss.ejb,nodename=ace]} on channel Channel ID b3ea68f8 (outbound) of Remoting connection 3c9d0b9d to localhost/127.0.0.1:8080

        main() : caught :  org.jboss.naming.remote.protocol.NamingIOException

        main() : message:  Failed to lookup

      main() :  end

      STACK TRACE

      • org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.IOException: javax.naming.NamingException: Lookup failed for 'java:jboss/exported/jdbc/tappds' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: No object bound for java:jboss/exported/jdbc/tappds [Root exception is java.lang.NullPointerException]]]

                     at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)

                     at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104)

                     at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)

                     at org.jboss.naming.remote.client.HaRemoteNamingStore$1.operation(HaRemoteNamingStore.java:276)

                     at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137)

                     at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)

                     at org.jboss.naming.remote.client.RemoteContext.lookupInternal(RemoteContext.java:104)

                     at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:93)

                     at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:146)

                     at javax.naming.InitialContext.lookup(Unknown Source)

                     at org.america3.gotest.database.TestMysqlDataSource.main(TestMysqlDataSource.java:58)

      Caused by: java.io.IOException: javax.naming.NamingException: Lookup failed for 'java:jboss/exported/jdbc/tappds' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: No object bound for java:jboss/exported/jdbc/tappds [Root exception is java.lang.NullPointerException]]

                     at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.readObject(WildFlyDataSource.java:143)

                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                     at java.lang.reflect.Method.invoke(Unknown Source)

                     at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)

                     at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)

                     at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)

                     at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)

                     at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

                     at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)

                     at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:156)

                     at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:149)

                     at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:59)

                     at org.jboss.naming.remote.protocol.v1.Protocol$1.handleClientMessage(Protocol.java:149)

                     at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver$1.run(RemoteNamingStoreV1.java:232)

                     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

                     at java.lang.Thread.run(Unknown Source)

      Caused by: javax.naming.NamingException: Lookup failed for 'java:jboss/exported/jdbc/tappds' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: No object bound for java:jboss/exported/jdbc/tappds [Root exception is java.lang.NullPointerException]]

                     at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)

                     at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)

                     at javax.naming.InitialContext.lookup(Unknown Source)

                     at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.readObject(WildFlyDataSource.java:140)

                     ... 18 more

      Caused by: javax.naming.NameNotFoundException: No object bound for java:jboss/exported/jdbc/tappds [Root exception is java.lang.NullPointerException]

                     at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:229)

                     at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)

                     ... 21 more

      Caused by: java.lang.NullPointerException

                     at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:167)

                     ... 22 more

      Caused by: an exception which occurred:

                     in object of type org.jboss.as.connector.subsystems.datasources.WildFlyDataSource

       

       

      D.  WildFly server.log lines that seem to apply


      On startup:

      ...

      12:40:29,270 INFO  WFLYCTL0028: Attribute 'enabled' in the resource at address '/subsystem=datasources/data-source=TappDS' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.

      ...

      12:40:30,331 INFO  WFLYJCA0001: Bound data source [java:jboss/exported/jdbc/tappds]

      ...

      12:40:31,221 INFO  HQ221003: trying to deploy queue jms.queue.goSvrSendQueue

       

      No lines were generated in the server.log either when the Queue was successfully looked up, or when the DataSource lookup failed.

        • 1. Re: Why does JNDI Queue lookup work but DataSource lookup fail?
          Justin Bertram Master

          Remote JNDI lookup of a JDBC datasource simply isn't supported as far as I know.  Here are a few reasons why it's not a good idea anyway:

           

          • It is not a good idea to have an unreliable client directly controlling the resources of your server (i.e. JDBC connections).  If the client loses network connectivity or crashes before it is able to close the connection then the connection will not be closed until the server is shutdown (i.e. it will be leaked).
          • It would likely be very slow.
          • Transaction propagation would be difficult if not impossible to support.

           

          I recommend you either enable database access directly from your application or deploy an EJB or other server-side component which can perform the database work you need and send your client the results.

          • 2. Re: Why does JNDI Queue lookup work but DataSource lookup fail?
            George Berish Novice

            Justin,

             

            Now I know what to look for, it was easy to confirm you are correct for all the good reasons you say.  You saved me a lot of wasted time searching. Thanks.

             

            Fortunately my goal isn't to use remote access of my server-side database.  It just seemed that while I was leaning to apply JDBC it would be easier to experiment with a standalone client.  I am still one a "trial and error - lots" learning curve, and  it would have saved the time needed to redeploy a Session Bean after ever change.  So now I know I need to learn to better automate deployment, which was on my list for later anyway.

            1 of 1 people found this helpful