4 Replies Latest reply on Aug 31, 2011 1:50 PM by beve

    How to setup jndi.properties for AS7

    saltnlight5

      Hi there,

       

      In older jboss server, I usually set jndi.properties like this:

       

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

      java.naming.provider.url=localhost:1099

       

      But these resulted in class not found in AS7, so I tried something close to matching what's avaible as maven dep like this:

       

      java.naming.factory.initial=org.jboss.as.naming.InitialContextFactory

      java.naming.provider.url=localhost:1099

       

      I don't get ClassNotFoundException, but then I can not list any binding names either. Can someone show how we properly lookup resources via JNDI API programmatically?

       

      Code I used to list JNDI resources:

          @Test

          public void testListJndi() throws Exception {

              Context ctx = null;

              try {

                  ctx = new InitialContext();

                  String contextName = "java:";

                  NamingEnumeration<NameClassPair> nameList = ctx.list(contextName);

                  while(nameList.hasMore()) {

                      NameClassPair name = nameList.next();

                      logger.info("{}", name);

                  }

              } finally {

                  if (ctx != null) {

                      try {

                          ctx.close();

                      } catch (NamingException e) {

                          logger.error("Failed to close JNDI context.", e);

                      }

                  }

              }

          }

        • 1. Re: How to setup jndi.properties for AS7
          dlofthouse

          At the moment remote JNDI is not yet supported, the following Jira issue is to address this: -

           

          https://issues.jboss.org/browse/AS7-1338

          • 2. Re: How to setup jndi.properties for AS7
            beve

            I'm a little confused about the following comment on that jira:

            We need to stop talking about "remote" JNDI. Clients will be able to use JNDI, but it will be a "local" JNDI view. This view will point to remote services and it might in some cases aggregate a very specific section of a remote tree, but there will be no remote access to a server JNDI tree.

            I'm not sure I understand the "local" JNDI view

             

            Lets say I have a remote client that needs to lookup JMS destinations from JNDI, what would that look like?

            Any chance someone could show a code example of this (does not have to be real or anything that can be used at the moment).

             

            Thanks,

             

            /Daniel

            • 3. Re: How to setup jndi.properties for AS7
              prasad.deshpande

              I'm not sure I understand the "local" JNDI view

               

              That means looking up JNDI from within your application (ear/war). Outside your application like using Remote clients are not yet supported.

               

              Lets say I have a remote client that needs to lookup JMS destinations from JNDI, what would that look like?

              Any chance someone could show a code example of this (does not have to be real or anything that can be used at the moment).

               

              This is not yet developed so nothing is yet available even to show as a sample example. But once it gets developed, code will be something like

               

              @Resource(lookup="java:jboss/jms/topic/testTopic") Topic testTopic; //assuming testTopic is bound to JNDI "java:jboss/jms/topic/testTopic"

              • 4. Re: How to setup jndi.properties for AS7
                beve

                This is not yet developed so nothing is yet available even to show as a sample example. But once it gets developed, code will be something like

                 

                @Resource(lookup="java:jboss/jms/topic/testTopic") Topic testTopic;

                //assuming testTopic is bound to JNDI "java:jboss/jms/topic/testTopic"

                 

                Ah, got it! Thanks clearing that up for me.

                 

                Regards,

                 

                /Daniel