0 Replies Latest reply on Jun 12, 2012 5:21 AM by martinluene

    JBoss7.1 JNDI subcontext handling failure

    martinluene

      Using JBoss7.1.2-NightlyBuild2012-04-30 - due to another fix - i observe strange behaviour within JNDI:

      First destrying a subcontext seems not work, the subcontext is still available afterwards.

      The second is, that after an unbind, the subcontext, which contained the object, is also gone.

      Instead i expect the subcontext to be still available, although it is empty now.

       

      Below are small test procedures for demonstration, at the indicated lines

      the first throws the RuntimeException, the second a javax.naming.NameNotFoundException.

       

      I execute these procedures within a SLSB on the application server.

      Is there a specific way needed to set up a naming context on server side, i just use "new InitialContext()"?

       

      Thanks,

      Martin

       

          public void testDestroySubcontext() throws NamingException {

              // Preparation

              Context ctx = new InitialContext();

              ctx.createSubcontext("root");

              Context sub1 = ctx.createSubcontext("root/sub1");

              sub1.rebind("NAME", "VALUE");

              assertEquals("Lookup object", "VALUE", ctx.lookup("root/sub1/NAME"));

              assertEquals("Lookup subcontext", "VALUE", sub1.lookup("NAME"));

       

              // test destroySubcontext

              ctx.destroySubcontext("root/sub1");

              try {

                  Context sub1Lookup = (Context) ctx.lookup("root/sub1");

      >>>>       throw new RuntimeException("Test failed, destroyed sub context still found: "

                          + sub1Lookup.getNameInNamespace());

              } catch (NameNotFoundException nnfe) {

                  // expected, but not thrown.

              }

          }

       

          public void testUnbind() throws NamingException {

              // Preparation

              Context ctx = new InitialContext();

              ctx.createSubcontext("root");

              Context sub1 = ctx.createSubcontext("root/sub1");

              sub1.rebind("NAME", "VALUE");

       

              assertEquals("Lookup object", "VALUE", ctx.lookup("root/sub1/NAME"));

              assertEquals("Lookup subcontext", "VALUE", sub1.lookup("NAME"));

              Context lookupCtx = (Context) ctx.lookup("root/sub1");

              assertEquals("Lookup before unbind", "root/sub1", lookupCtx.getNameInNamespace());

       

              // test unbind

              ctx.unbind("root/sub1/NAME");

              try {

                  Object item = ctx.lookup("root/sub1/NAME");

                  throw new RuntimeException("Test failed, unbound object still found" + item);

              } catch (NameNotFoundException nnfe) {

                  // expected, unbound object no longer available.

              }

       

              // sub context shall be still available, as stated in java doc for javax.naming.Context.unbind().

      >>>>  Context lookupAgainCtx = (Context) ctx.lookup("root/sub1");

              assertEquals("Lookup after unbin", "root/sub1", lookupAgainCtx.getNameInNamespace());

          }

         

      Caused by: javax.naming.NameNotFoundException: root/sub1 -- service jboss.naming.context.java.root.sub1

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

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

          at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:119)

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

          at javax.naming.InitialContext.lookup(InitialContext.java:392)

          at com.jcoffee.base.global.naming.test.TestJNDIUtilitiesImpl.testUnbind(TestJNDIUtilitiesImpl.java:235)