10 Replies Latest reply on Sep 13, 2007 1:41 AM by jaikiran pai

    basic JNDI beginners problems - cant do look up from applica

    William Woodman Master

      just trying to get to grips with JBOSS AS4.2 and new to the environment. Really trying to get to EJB3 but doing it bit by bit and want to be able to call session bean services from a test application client - that i can run in eclipse.

      deployed 4.2 and configured a My sql XA datasource as follows.

      
      <datasources>
       <xa-datasource>
       <jndi-name>jdbc/willsDS</jndi-name>
       <use-java-context>false</use-java-context>
       <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
       <xa-datasource-property
       name="URL">
       jdbc:mysql://localhost:3306/test
       </xa-datasource-property>
       <user-name>will</user-name>
       <password>will</password>
       <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
       <max-pool-size>5</max-pool-size>
       <min-pool-size>1</min-pool-size>
      
       <blocking-timeout-millis>2000</blocking-timeout-millis>
       <idle-timeout-minutes>2</idle-timeout-minutes>
       <track-connection-by-tx>true</track-connection-by-tx>
       <no-tx-separate-pools>false</no-tx-separate-pools>
      
       <exception-sorter-class-name>
       org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
       </exception-sorter-class-name>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
      
       </xa-datasource>
      </datasources>
      


      This all goes well - and when i start the server inside eclipse i can see the datasource in the JNDIView tree

      i've registered the datasource in the global tree and not the java: default part as the JNDI FAQ says you cant see the java: tree unless its in the same VM.

      i've checked netstat - a and port 1099 is being listened on when i run the server up.

      next created a simple client app (as an EJB project in eclipse to pickup the AS libraries if nothing else)

      my simple app client looks like this - at the mo i'm just trying to get a simple JNDI lookup to the datasource in the AS (no DI here as its an standalone client)

      
      package org;
      
      import java.sql.Connection;
      import java.util.Hashtable;
      
      import javax.naming.InitialContext;
      import javax.sql.DataSource;
      
      
      /**
      * @author Will
      *
      */
      public class Test
      {
      
      
       public static void main(String[] args) throws Exception
       {
      
      
       InitialContext ctx = getInitialContext();
       DataSource ds;
       Connection conn;
      
       //llookup ds via jndi in global tree - using jnp://localhost:1099 - see helper function above
       ds = (DataSource) ctx.lookup("jdbc/willDS");
       conn = ds.getConnection();
       conn.close();
      
      
       }
      
       public static InitialContext getInitialContext() throws Exception
       {
       Hashtable props = getInitialContextProperties();
       return new InitialContext(props);
       }
      
       private static Hashtable getInitialContextProperties()
       {
      
       Hashtable props = new Hashtable();
       props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       props.put("javax.naming.Context.PROVIDER_URL","jnp://localhost:1099");
       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
       return props;
       }
      }
      


      when i run the app however i get varying errors depending on whether i set the provider_url or not.

      code shows me setting the provider_url and get error


      Exception in thread "main" javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
      at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1317)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1446)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at org.Test.main(Test.java:32)
      Caused by: java.net.SocketTimeoutException: Receive timed out
      at java.net.PlainDatagramSocketImpl.receive0(Native Method)
      at java.net.PlainDatagramSocketImpl.receive(Unknown Source)
      at java.net.DatagramSocket.receive(Unknown Source)
      at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1287)
      ... 5 more


      on an earlier go i got errors about cant find bound class jdbc - but i cant get that at present - and now stuck on the above.

      I'll never progress to anything smarter if i cant sort the basics out - what am i doing wrong, any ideas please?



        • 1. Re: basic JNDI beginners problems - cant do look up from app
          jaikiran pai Master

          Which operating system? The exception stacktrace shows a

          Caused by: java.net.SocketTimeoutException: Receive timed out


          I guess, the client is not able to resolve localhost.

          • 2. Re: basic JNDI beginners problems - cant do look up from app
            William Woodman Master

            Hello Jaikiran,

            yes the client and the AS are both running on the same machine (my laptop) running windows.

            I am using callisto eclipse as dev IDE and have run he AS server up from eclipse by using the start server action on the servers tab.

            That works fine and I can view the JMX console etc on localhost:8080 as youd expect, and my Datasource is visible in the JNDIView in the global section (see config line in the DS deploy descriptor.

            I build the client as an EJB project in same eclipse (I started as EJB project as eventually i've trying to get to grips with EJB but also cos it includes the AS libraries in the path.

            however the code is as shown and is a straight pojo with a main - which i run inside eclipse by call run as application (i dont deploy it to the server as it has no managed classes at this point - i was just trying to make sure I could get a JNDI ref to the willDS

            cheers

            • 3. Re: basic JNDI beginners problems - cant do look up from app
              jaikiran pai Master

              Do you have any software installed which might be blocking the client from accessing the localhost at port 1099? As far as the code is concerned, i dont see any issues with it.

              • 5. Re: basic JNDI beginners problems - cant do look up from app
                William Woodman Master

                jaikiran

                thanks for the reply - its a little late at night - i tried the same code on another laptop (not my works one) and I do seem to get a lookup - so theres probably something in the works laptop blocking the lookup (though i'm not sure what as the the fw is disabled - but we have odessy as port authent service when connecting to lan and may thats impacting the connection - i'll have a look tomorrow.

                however general query - if I remove the line
                <use-java-context>false</use-java-context>
                from my DS spec - then the DS gets put in the 'java:' tree in the AS jndi tree, and when i try to look that up it says 'java:' is not bound from the standalone application.

                is the the 'java:' branch only available to applications deployed into the AS server ? therefore i was using servlets and other clients deployed to the AS i can use the default 'java: ' branch - but if i want remote clients to access them i need to put them in global JNDI tree?

                If i declare a @Remote annotation for a session bean - does that go into the global or the 'java:' tree? if the latter how are external apps expected to find the sessionBean JNDI references?

                kind regards Will

                • 6. Re: basic JNDI beginners problems - cant do look up from app
                  Sandor Fiedler Newbie

                  hi will!

                  the java: namespace implies (or better specifies) the namespace only available in the same jvm. so for remote access all name bindings have to be in the global namespace unless you're using a facade to do the jobs for your client.

                  hope this helps. regards
                  /sandor/

                  • 7. Re: basic JNDI beginners problems - cant do look up from app
                    jaikiran pai Master

                    In addition to what sandor mentioned, your bean with the @Remote annotation is going to be bound by default in the global jndi namespace

                    • 8. Re: basic JNDI beginners problems - cant do look up from app
                      William Woodman Master

                      still having a problem here that I dont seem to be able to resolve

                      I did a search on goole and got similiar people who have had similar problem and i'm note sure any of them seem to quite get to a resolution

                      see www.jboss.com/?module=bb&op=viewtopic&t=68072 and
                      www.jboss.com/?module=bb&op=viewtopic&t=75499
                      and www.theserverside.com/discussions/thread.tss?thread_id=32699

                      etc .

                      still battling with this - on my works computer.

                      I eventually got the passwords from support teams and diabled the local firewall (intengrity flex agent) and this doesnt seem to fix it either - i'ven turned the firwall back on and configured it to accept open port 1099 for trusted zoen access (localhost)

                      I can ping localhost from the cmd shell so the dns for localhost seems to resolve. Any ideas anyone

                      • 9. Re: basic JNDI beginners problems - cant do look up from app
                        Deep Blue Li Newbie

                        Check what IP address your JBoss server is binded.

                        You can try to add "-b 0.0.0.0" at the program argument (It is under "Run" --> "Open Run Dialog" --> choose your JBoss server --> navigate to the "Arguments" tab) when you start JBoss:

                        0.0.0.0 is to make JBoss listen to any address

                        • 10. Re: basic JNDI beginners problems - cant do look up from app
                          jaikiran pai Master

                           

                          "wiggy" wrote:
                          still having a problem here that I dont seem to be able to resolve

                          I did a search on goole and got similiar people who have had similar problem and i'm note sure any of them seem to quite get to a resolution

                          see www.jboss.com/?module=bb&op=viewtopic&t=68072 and
                          www.jboss.com/?module=bb&op=viewtopic&t=75499
                          and www.theserverside.com/discussions/thread.tss?thread_id=32699

                          etc .

                          still battling with this - on my works computer.

                          I eventually got the passwords from support teams and diabled the local firewall (intengrity flex agent) and this doesnt seem to fix it either - i'ven turned the firwall back on and configured it to accept open port 1099 for trusted zoen access (localhost)

                          I can ping localhost from the cmd shell so the dns for localhost seems to resolve. Any ideas anyone



                          wiggy,

                          I tried out a sample test on my local setup to see if i was missing something. Everything worked fine for me. I then went through your post again and found the problem. Here it is, you are using:

                          private static Hashtable getInitialContextProperties()
                          {

                          Hashtable props = new Hashtable();
                          props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                          props.put("javax.naming.Context.PROVIDER_URL","jnp://localhost:1099");
                          props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
                          return props;
                          }


                          That key, javax.naming.Context.PROVIDER_URL is incorrect. It should be
                          java.naming.provider.url. Also, it always safer to use the constants meant for these as follows:


                          private static Hashtable getInitialContextProperties()
                           {
                          Hashtable props = new Hashtable();
                           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" );
                           return props;
                           }


                          Try it out and see if it works on your setup.