3 Replies Latest reply on Oct 24, 2013 2:36 PM by Srini S

    unable to invoke jndi (JBoss EAP6)call from java program

    Srini S Newbie

      Hi All,

       

      I have setup a datasource in JBoss EAP6 admin console and 'Test DB Connection' also successfully.

      Step 1-> Started standalone.bat file

      Step 2-> Tried to run the below code as standalone app and getting below error.

       

      Pls let me know what went wrong in the code.

       

      Thanks in advance for help.

       

      Below the admin console where the ports running and datasource details.

      admin console.PNG

      ErrorDesc.PNG

      Below is my code snippet to invoke the jndi.

      ----------------------------------

      Properties env = new Properties();

        env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");

        env.put(Context.PROVIDER_URL,"localhost:9999");

        env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");

        System.out.println("env prop done...");

        InitialContext ic = new InitialContext(env);

        System.out.println("before look up...");

        Object obj = ic.lookup("java:jboss/datasources/OracleDS");

        System.out.println("obj:"+obj);

      --------------------------------------

       

      Thanks

        • 1. Re: unable to invoke jndi (JBoss EAP6)call from java program
          ehugonnet Apprentice

          You shouldn't be using JNP as it has been replaced with jboss-remoting.

          Look into this for some example : https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

          • 3. Re: unable to invoke jndi (JBoss EAP6)call from java program
            Srini S Newbie

            Thanks for your reply.

             

            I have updated the code as per your suggestion.  Now when I run the program I am getting below error. Below the console logs confirms (in red) jndi is available.

            User details supplied in code(myadmin/myadmin123!) are part of ApplicationRealm.


            Pls advice.

             

            Server Console log

            -----------------------------------

            00:00:19,710 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on 127.0.0.1:4447

            00:00:19,710 INFO  [org.jboss.as.remoting] (MSC service thread 1-7) JBAS017100: Listening on 127.0.0.1:9999

            00:00:19,723 INFO  [org.apache.coyote.http11] (MSC service thread 1-5) JBWEB003001: Coyote HTTP/1.1 initializing on : http-/127.0.0.1:8080

            00:00:19,726 INFO  [org.apache.coyote.http11] (MSC service thread 1-5) JBWEB003000: Coyote HTTP/1.1 starting on: http-/127.0.0.1:8080

            00:00:19,907 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/OracleDS]

            00:00:19,907 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:/srini/oracle]

            00:00:19,907 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]

            00:00:20,159 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management

            -----------------------------------------------------

            Log

            -------------------------------

            Oct 25, 2013 12:01:59 AM org.xnio.Xnio <clinit>

            INFO: XNIO Version 3.0.7.GA-redhat-1

            Oct 25, 2013 12:01:59 AM org.xnio.nio.NioXnio <clinit>

            INFO: XNIO NIO Implementation Version 3.0.7.GA-redhat-1

            Oct 25, 2013 12:01:59 AM org.jboss.remoting3.EndpointImpl <clinit>

            INFO: JBoss Remoting version 3.2.16.GA-redhat-1

            before look up...

            javax.naming.NameNotFoundException: jboss/datasources/OracleDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.OracleDS

              at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)

              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)

              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:174)

              at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)

              at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

              at java.lang.Thread.run(Thread.java:619)

            --------------------------------

             

            Updated code snippet

            ----------------------------

            Properties props = new Properties();

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

              props.put(Context.PROVIDER_URL, "remote://localhost:4447");

              props.put(Context.SECURITY_PRINCIPAL, "myadmin");

              props.put(Context.SECURITY_CREDENTIALS, "myadmin123!");

              Context initialContext = new InitialContext(props);

              System.out.println("before look up...");

              Connection con = null;

              try{

              DataSource ds = (javax.sql.DataSource)initialContext.lookup("java:jboss/datasources/OracleDS");

              con = ds.getConnection();

              }catch(Exception e){

              e.printStackTrace();

              }

              System.out.println("con:"+con);

            ----------------------------