4 Replies Latest reply on Jul 17, 2009 8:53 AM by ram mannam

    JNDI look up from ServletContextListener

    Nikita - Newbie

      Hi All,

      I've problem porting my application to JBoss 5.0.0.GA.

      My application war-module has ServletContextListener (class implemented javax.servlet.ServletContextListener). This listener activates during war module initialization and makes several calls to session ejbs.

      It worked in JBoss 4.2.2, but in 5.0 I'd got javax.naming.NameNotFoundException, when I was looking up session ejb home interface.

      The same code works well after ear initialization completed, but during initialization it fails.

      Thanx, Nikita

        • 1. Re: JNDI look up from ServletContextListener
          Nikita - Newbie

          I've created very simple test application to demonstrate issue.

          It works fine when normal servlet calls EJB:

          InitialContext ctx = new InitialContext();
          BPServerManagerHome home = (BPServerManagerHome) PortableRemoteObject
           .narrow(ctx.lookup("ejtest/BPServerManagerBean"),
           BPServerManagerHome.class);
          System.out.println("EJB call res: " + home.create().doit());
          


          But the same code fails when it executed from Starter (ServletContextListener immplementation):
          20:16:48,622 ERROR [STDERR] javax.naming.NameNotFoundException: BPServerManagerBean not bound
          20:16:48,622 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
          20:16:48,622 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
          20:16:48,622 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
          20:16:48,622 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
          20:16:48,622 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:399)
          20:16:48,622 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
          20:16:48,622 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
          20:16:48,622 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
          20:16:48,622 ERROR [STDERR] at Starter.contextInitialized(Starter.java:17)
          20:16:48,622 ERROR [STDERR] at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
          20:16:48,622 ERROR [STDERR] at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
          20:16:48,622 ERROR [STDERR] at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:367)
          20:16:48,622 ERROR [STDERR] at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:146)
          20:16:48,622 ERROR [STDERR] at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:460)
          20:16:48,622 ERROR [STDERR] at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
          20:16:48,622 ERROR [STDERR] at org.jboss.web.deployers.WebModule.start(WebModule.java:96)
          


          I've put ear, sources and build script for this application here:
          http://www.abisoft.biz/~nbelov/EJTest.zip

          • 2. Re: JNDI look up from ServletContextListener
            jaikiran pai Master

            Looks like a deployment ordering issue. I guess the war is deployed before the ejb jar. Similar to what is noted here http://www.jboss.org/index.html?module=bb&op=viewtopic&t=146745&start=0#4213523

            • 3. Re: JNDI look up from ServletContextListener
              Nikita - Newbie

              Yes. Looks like you were right. I've switched to JBoss 5.0.1.GA, and added to conf\bootstrap\deployers.xml:

              <bean name="topContextComparator">
               <constructor factoryClass="org.jboss.system.deployers.LegacyDeploymentContextComparator" factoryMethod="getInstance"/>
               <property name="suffixOrder" class="java.util.Map">
               <map keyClass="java.lang.String" valueClass="java.lang.Integer">
               <entry>
               <key>.war</key>
               <value>700</value>
               </entry>
               </map>
               </property>
              </bean>
              

              Now it works. But I think it is only tempory solution. I hope future jboss versions will load ejb-jars before wars.

              • 4. Re: JNDI look up from ServletContextListener
                ram mannam Newbie

                xml lines did not appear in the previous post.


                <bean name="topContextComparator">
                 <constructor factoryClass="org.jboss.system.deployers.LegacyDeploymentContextComparator" factoryMethod="getInstance"/>
                 <property name="suffixOrder" class="java.util.Map">
                 <map keyClass="java.lang.String" valueClass="java.lang.Integer">
                 <entry>
                 <key>.war</key>
                 <value>700</value>
                 </entry>
                 </map>
                 </property>