4 Replies Latest reply on Jan 13, 2007 4:59 AM by fudeus

    Problem getting Datasource vi JNDI

    mjais

      hello

      I am trying to get the Quartz scheduler running:

      I have a local jboss (4.0.3) running on my machine and configured the Quartz datasource.

      via the JBoss JMX console I can see that the datasource is bound:


      java: Namespace

      +- jaas (class: javax.naming.Context)
      .............
      +- jdbc (class: org.jnp.interfaces.NamingContext)
      | +- QuartzDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
      | +- QuartzNoTxDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
      ..............


      I wrote the following client programme to access the datasource:

      class ContextTest {

      public static DataSource getDataSource(String dataSourceJndiName) {
      DataSource dataSource = null;

      Properties prop = new Properties();
      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      prop.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
      prop.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      try {
      Context ctx = new InitialContext(prop);
      dataSource = (DataSource) ctx.lookup(dataSourceJndiName);

      } catch (ClassCastException cce) {
      cce.printStackTrace();
      } catch (NamingException ne) {
      ne.printStackTrace();
      }

      return dataSource;
      }

      public static void main(String[] args) {
      DataSource ds = getDataSource("java:comp/env/jdbc/QuartzDS");
      System.out.println(ds.toString());
      }
      }


      and I get this error:
      javax.naming.NameNotFoundException: comp 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:252)


      I also tried many other combinations for the JNDI Name, but I never managed
      to get the Datasource.
      calling the code from within a JSF application (deployed on the JBoss where the
      Quartz datasource is) doesn't work either.

      any idea what's wrong here ?

      Markus







        • 1. Re: Problem getting Datasource vi JNDI
          mjais

          I now found out that I can not access the "java:" context outside of JBoss.

          when I try to access "Quartz" which is in the Global JNDI Namespace I get this error:

          java.lang.ClassCastException: javax.naming.Reference
          at ContextTest.getDataSource(ContextTest.java:33)
          at ContextTest.main(ContextTest.java:56)
          Exception in thread "main" java.lang.NullPointerException
          at ContextTest.main(ContextTest.java:58)


          the jbossallclient.jar is in my classpath.

          Markus

          • 2. Re: Problem getting Datasource vi JNDI
            prakah

            Hello Markus,

            Try with the jndi name as "java:jdbc/QuartzDS". This might solve your problem.

            • 3. Re: Problem getting Datasource vi JNDI
              mjais

              hi Prakash

              thanks for your tip. I already tried all possible combinations.
              none of them worked.

              Markus

              • 4. Re: Problem getting Datasource vi JNDI

                 

                "mjais" wrote:
                I now found out that I can not access the "java:" context outside of JBoss.


                The "java:"-context is only valid for "in-vm"-lookups.


                "mjais" wrote:
                calling the code from within a JSF application (deployed on the JBoss where the
                Quartz datasource is) doesn't work either


                Calls from within JBoss should succeed using ctx.lookup("java:/jdbc/QuartzDS")