7 Replies Latest reply on Jun 7, 2005 2:29 AM by Daniel Kaplan

    NameNotFoundException in my servlet

    Daniel Kaplan Newbie

      I'm getting a namenotfoundexception when I"m trying to execute this line:

      Destination destination =
       (Queue) jndiContext.lookup("java:comp/env/queue/TestMessageQueue");

      I really don't understand why because when jboss starts up it says this:
      19:38:29,500 INFO [TestMessageQueue] setJNDIName Bound to JNDI name: queue/TestMessageQueue
      I've tried using java:comp/env/jms/queue/TestMessageQueue too, nothing works.

      This is my ejb-jar.xml

       <description>Just a Test</description>

      Am I giving enough information for someone to be able to help me with this problem?

        • 2. Re: NameNotFoundException in my servlet
          Anil Saldanha Master

          Go to JMX Console. Click on the link representing "JNDIView" and "list()" should list all the objects bound in JNDI. If your object is not bound, something wrong with config.

          • 3. Re: NameNotFoundException in my servlet
            Daniel Kaplan Newbie


            "anil.saldhana@jboss.com" wrote:
            Go to JMX Console. Click on the link representing "JNDIView" and "list()" should list all the objects bound in JNDI. If your object is not bound, something wrong with config.

            If by object, you mean my MDB then yeah it shows up. Also it mentions the queue that i'm trying to look up. Here's the whole output:

            Ejb Module: pmdevapp.jar
            java:comp namespace of the PMSessionBean bean:
             +- env (class: org.jnp.interfaces.NamingContext)
            java:comp namespace of the WRSessionBean bean:
             +- env (class: org.jnp.interfaces.NamingContext)
            java:comp namespace of the TestMessageEJB bean:
             +- env (class: org.jnp.interfaces.NamingContext)
            java: Namespace
             +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
             +- DefaultDS (class: javax.sql.DataSource)
             +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
             +- OracleDS (class: javax.sql.DataSource)
             +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
             +- comp (class: javax.naming.Context)
             +- jdbc (class: org.jnp.interfaces.NamingContext)
             | +- PMDataSource (class: javax.sql.DataSource)
             +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
             +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
             +- jaas (class: javax.naming.Context)
             | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
             | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
             | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
             +- timedCacheFactory (class: javax.naming.Context)
            Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
             +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
             +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
             +- Mail (class: javax.mail.Session)
             +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
             +- TransactionManager (class: org.jboss.tm.TxManager)
            Global JNDI Namespace
             +- jmx (class: org.jnp.interfaces.NamingContext)
             | +- invoker (class: org.jnp.interfaces.NamingContext)
             | | +- RMIAdaptor (proxy: $Proxy36 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
             | +- rmi (class: org.jnp.interfaces.NamingContext)
             | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
             +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
             +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
             +- PMSessionBean (proxy: $Proxy59 implements interface com.webreach.pm.as.PMSessionRemoteHome,interface javax.ejb.Handle)
             +- UserTransactionSessionFactory (proxy: $Proxy11 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
             +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
             +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
             +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
             +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
             +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
             +- local (class: org.jnp.interfaces.NamingContext)
             | +- WRSessionBean@8606710 (proxy: $Proxy55 implements interface com.webreach.pm.as.WRSessionLocalHome)
             | +- PMSessionBean@26359981 (proxy: $Proxy53 implements interface com.webreach.pm.as.PMSessionLocalHome)
             +- queue (class: org.jnp.interfaces.NamingContext)
             | +- D (class: org.jboss.mq.SpyQueue)
             | +- C (class: org.jboss.mq.SpyQueue)
             | +- B (class: org.jboss.mq.SpyQueue)
             | +- A (class: org.jboss.mq.SpyQueue)
             | +- testQueue (class: org.jboss.mq.SpyQueue)
             | +- TestMessageQueue (class: org.jboss.mq.SpyQueue)
             | +- TestMessageEJB (class: org.jboss.mq.SpyQueue)
             | +- ex (class: org.jboss.mq.SpyQueue)
             | +- DLQ (class: org.jboss.mq.SpyQueue)
             +- topic (class: org.jnp.interfaces.NamingContext)
             | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
             | +- testTopic (class: org.jboss.mq.SpyTopic)
             | +- securedTopic (class: org.jboss.mq.SpyTopic)
             +- console (class: org.jnp.interfaces.NamingContext)
             | +- PluginManager (proxy: $Proxy37 implements interface org.jboss.console.manager.PluginManagerMBean)
             +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
             +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
             +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
             +- WRSessionBean (proxy: $Proxy62 implements interface com.webreach.pm.as.WRSessionRemoteHome,interface javax.ejb.Handle)
             +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)

            Can you make any sense of that (cause I can't). I'll also paste more of what my servlet is trying to do:

            Context jndiContext = new InitialContext();
             Destination destination =
             (Queue) jndiContext.lookup("java:comp/env/queue/TestMessageQueue");
             ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("java:comp/env/jms/ConnectionFactory");
             javax.jms.Connection connection = connectionFactory.createConnection();
             javax.jms.Session session = connection.createSession(false,
             MessageProducer messageProducer = session.createProducer(destination);
             TextMessage message = session.createTextMessage();
             for (int i = 0; i < 10; i++) {
             message.setText("This is message " + (i + 1));
             System.out.println("Sending message: " +

            That connection factory is totally made up. I'm not sure what i'm supposed to use for that, but, again, the line that's causing the problem is the line that comes before it.

            Here's the stack trace when i go to the servlet:

            19:48:52,890 INFO [STDOUT] write javax.naming.NameNotFoundException: queue not bound
            19:48:52,890 INFO [STDOUT] write at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
            19:48:52,890 INFO [STDOUT] write at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
            19:48:52,890 INFO [STDOUT] write at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
            19:48:52,890 INFO [STDOUT] write at org.jnp.server.NamingServer.lookup(NamingServer.java:249)
            19:48:52,890 INFO [STDOUT] write at org.jnp.server.NamingServer.lookup(NamingServer.java:252)
            19:48:52,890 INFO [STDOUT] write at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
            19:48:52,890 INFO [STDOUT] write at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:701)
            19:48:52,890 INFO [STDOUT] write at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
            19:48:52,890 INFO [STDOUT] write at javax.naming.InitialContext.lookup(InitialContext.java:351)
            19:48:52,890 INFO [STDOUT] write at com.webreach.pm.web.ServiceLocator.lookup(ServiceLocator.java:38)
            19:48:52,890 INFO [STDOUT] write at com.webreach.pm.web.ServiceLocator.getDestination(ServiceLocator.ja
            19:48:52,890 INFO [STDOUT] write at com.webreach.pm.web.UserServlet.processRequest(UserServlet.java:707
            19:48:52,906 INFO [STDOUT] write at com.webreach.pm.web.UserServlet.doGet(UserServlet.java:794)
            19:48:52,906 INFO [STDOUT] write at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
            19:48:52,906 INFO [STDOUT] write at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
            19:48:52,906 INFO [STDOUT] write at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ap
            19:48:52,906 INFO [STDOUT] write at org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicatio
            19:48:52,906 INFO [STDOUT] write at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeader

            Is there any more information i can provide that would help?

            • 4. Re: NameNotFoundException in my servlet
              Anil Saldanha Master

              Looks like there may be an additional jndi.properties somewhere that is being used instead of the one you provided.

              Have you specified a jndi.properties file?

              • 5. Re: NameNotFoundException in my servlet
                Daniel Kaplan Newbie

                to tell you the truth i don't know. Another employee set this up and I'm not at work right now so I can't check. Would you mind explaining what led you to believe what you just said?


                • 6. Re: NameNotFoundException in my servlet
                  Anil Saldanha Master

                  Give the following a shot

                  Destination destination =
                   (Queue) jndiContext.lookup("queue/TestMessageQueue");

                  On careful examination, seems like the queue is bound to the global namespace as the following log message explains:
                  19:38:29,500 INFO [TestMessageQueue] setJNDIName Bound to JNDI name: queue/TestMessageQueue

                  • 7. Re: NameNotFoundException in my servlet
                    Daniel Kaplan Newbie

                    Alright, I promise to try that first thing in the morning. Thanks a lot for sticking with me through this whole thing. If it doesn't work I hope you won't give up on me :)

                    Just FYI, i do have two stateless session beans working right now with JBoss. The only way i could get them to work was if i put a tag into my web.xml file. I think the tag was something like <ejb-local-interface>...</ejb-local-interface> Without those tags i would get similar problems (I don't remember if they were exact problems).

                    Would a MDB need a similar type of tag in the web.xml? I've read a bunch of tutorials before i posted this question and none of them used examples where the web.xml had to be changed.