0 Replies Latest reply on May 19, 2006 5:46 PM by Aditya Poosarla

    JNDI lookup problem

    Aditya Poosarla Newbie

      Hi,

      I am having a problem looking up for jndi from my webapp. I am using jboss-4.0.4.CR2 and java 1.5. Right now in my application I don't have any ejb's. I only have a few servlets. My application is currently bundled as a .war file.

      The jndi configuration I have is as follows:
      web.xml

      <resource-env-ref>
      <resource-env-ref-name>QuestionWriter1</resource-env-ref-name>
      <resource-env-ref-type>com.mycompany.survey.QuestionWriter1</resource-env-ref-type>
      </resource-env-ref>


      I have several QuestionWriters.

      In the jboss-web.xml my config is
      <resource-env-ref>
      <resource-env-ref-name>QuestionWriter1</resource-env-ref-name>
      <jndi-name>java:/QuestionWriter1</jndi-name>
      </resource-env-ref>


      I have a resource-env-ref in jboss-web for each resource-env-ref tag in the web.xml

      The way I look in my code is
      Context env = (Context) new InitialContext().lookup("java:comp/env");
      qw = (QuestionWriter) env.lookup("QuestionWriter1");


      Can anyone tell me what is that I am doing wrong. I try to look into the jndi view in the jmx-console and I dont find any of there QuestionWriters.

      Is there any other configuration I am missing. I place my war file in the deploy folder of jboss. I am using the ejb3-clustered instance of jboss this is because in the future we are going to have ejb's.

      The exception it throws is as follows

      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: QuestionWriter1 not bound]
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at com.mycomp.survey.research.QuestionWriter.getInstance(QuestionWriter.java:73)
       at org.apache.jsp.bonus_005fdollars.preview_jsp._jspService(preview_jsp.java:132)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
       at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
       at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
       at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
       at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:614)
       at net.mycomp.web.RegionWriterTag.doStartTag(Unknown Source)
       at org.apache.jsp.templates.main_jsp._jspService(main_jsp.java:137)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
       at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
       at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
       at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
       at org.apache.struts.tiles.ActionComponentServlet.doForward(ActionComponentServlet.java:453)
       at org.apache.struts.tiles.ActionComponentServlet.processActionForward(ActionComponentServlet.java:180)
       at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
       at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.EmailVerificationFilter.doFilter(EmailVerificationFilter.java:160)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.SecurePagesFilter.doFilter(SecurePagesFilter.java:97)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:126)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.TrackingFilter.doFilter(TrackingFilter.java:45)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.UserActivityLog.doFilter(UserActivityLog.java:100)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.PauseFilter.doFilter(PauseFilter.java:33)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.PauseFilter.doFilter(PauseFilter.java:33)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.PauseFilter.doFilter(PauseFilter.java:33)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at net.mycomp.filter.PauseFilter.doFilter(PauseFilter.java:33)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
       at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
       at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754)
       at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:684)
       at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:876)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.naming.NameNotFoundException: QuestionWriter1 not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061)
       ... 86 more



      I have the same code running in tomcat with the <Resource tag in the server.xml of tomcat.

      Thanks in advance.
      Aditya