2 Replies Latest reply on Jun 4, 2013 3:54 AM by tonyweb

    InitialContext binding unexpected behavior after hot deploy ...

      Hi guys and girls,

      I'm a new GateIn portlet developer and I'm here to ask for your help.

       

      I'm using GateIn 3.5 on Tomcat 7.

      My need is to create an object in a thread (I'm using quartz-2.1.7.jar) and put it into InitialContext (so I can get it again using lookup from InitialContext).

       

      [code]

      // In Thread ...

      long tm = System.currentTimeMillis();

      String newVar = TestBindJNDIPortlet.VAR_TO_BIND_BASE + "_" + tm;

       

       

      InitialContext ctx = new InitialContext();

      ctx.bind(newVar, "" + tm);

       

       

      // Later in "portlet code" ...

      InitialContext ctx = new InitialContext();

      String readVal = (String) ctx.lookup(var);

      [/code]

       

       

       

      This way I can bind a value to InitialContext and read it without issues.

       

       

      However, when I hot-deploy the portlet again (even without modifications) and try to do again Bind+Read, I can bind the value (in thread) but from portlet I can't read it (NameNotFoundException)

      ... it seems I'm "using" two different InitialContext, one "seen" from the Thread and one "seen" from portlet code.

       

       

      Can anyone, please, tell me what am I missing?

       

       

      If this is the intended/normal behavior, is there a way to do what I'm trying to do?

      I'm forced to "register" the object in InitialContext since I'm using some code that looks up the "resource" from there.

       

       

      Thanks in advance and

       

       

      Best Regards,

      Antonio

        • 1. Re: InitialContext binding unexpected behavior after hot deploy ...
          hoang_to

          It seems to me that once you redeploy the portlet, the class loader of portlet application is reassigned (to a new instance of WebAppClassLoader)  AND your JNDI factory class is available in a .jar under WEB-INF/lib, so the JNDI naming is recreated.

           

          If i were you, i would put a breakpoint at line 240 of InitialContext (in JDK code) to see what is JNDI factory class in use. Then, check if .jar containing that class exists in both tomcat/lib and WEB-INF/lib. If it is the case, let's remove the one under WEB-INF/lib

          • 2. Re: InitialContext binding unexpected behavior after hot deploy ...

            Thank you for looking into it.

            I'll try to do what you suggested (I never "debugged" JDK code) and see if I can understand what's happening.

             

            Regards,

            Antonio