7 Replies Latest reply on May 26, 2008 2:09 AM by jaikiran

    Problem by jndi-lookup from Tomcat to JBoss

    thomas2008ch

      Hi all,

      I use the XDoclet to build EJB2-porject. The EJB2-project is deployed in JBoss 4.2.2. GA.

      I can access/connect to the bean from an jsp (index.jsp) in a war:

      ...
      <body>
      <%
       com.zoo.Tiger tiger = null;
       try{
       com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
       tiger = home.create();
      
       }catch(Exception exception)
       {
      
       }
      %>
      <b><%= tiger.roar() %></b>
      </body>
      ...
      


      The war is included within an ear deployed on JBoss.

      I can even access/connect the bean on the server with a standalone java:

      public class TestClient {
      
       public static void main(String[] args) {
       Tiger tiger = null;
       try {
       TigerHome home = TigerUtil.getHome();
       tiger = home.create();
       System.out.println(tiger.roar());
      
       } catch (Exception exception) {
       exception.printStackTrace();
       }
       }
      }
      


      With a jndi.properties:

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost:1099
      


      Now I deploy the web/war on Tomcat 6 and try to access/connect to the bean on JBoss. But it failed. My "index.jsp" looks as follow:

      <body>
      <%
       Properties props = new Properties();
       props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
       props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      
       com.zoo.Tiger tiger = null;
       try{
       com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
       tiger = home.create();
      
       }catch(Exception exception)
       {
      
       }
      %>
      <b><%= tiger.roar() %></b>
      </body>


        • 1. Re: Problem by jndi-lookup from Tomcat to JBoss
          jaikiran

           

          But it failed.

          Failed = What exactly happened? Do you see any exception? Also, you would want to do a better job with the exception handling:


          try{
          com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
          tiger = home.create();

          }catch(Exception exception)
          {

          }



          Atleast, print out the stacktrace

          try{
           com.zoo.TigerHome home = com.zoo.TigerUtil.getHome();
           tiger = home.create();
          
           }catch(Exception exception)
           {
           exception.printStackTrace();
           }


          • 2. Re: Problem by jndi-lookup from Tomcat to JBoss
            thomas2008ch

            Surely you are right.

            Here is the exceptions I got in the browser:

            exception
            
            org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 29
            
            26: exception.printStackTrace();
            27: }
            28: %>
            29: <b><%= tiger.roar() %></b>
            30:
            31:
            32: </body>
            
            
            Stacktrace:
             org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
             org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
             org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
             org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
             javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            
            
            root cause
            
            java.lang.NullPointerException
             org.apache.jsp.index_jsp._jspService(index_jsp.java:87)
             org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
             javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
             org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
             org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
             org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
             javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            
            




            • 3. Re: Problem by jndi-lookup from Tomcat to JBoss
              thomas2008ch

              In the log file I got the full stack trace:

              SCHWERWIEGEND: Servlet.service() for servlet jsp threw exception
              java.lang.NullPointerException
               at org.apache.jsp.index_jsp._jspService(index_jsp.java:87)
               at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
               at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
               at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
               at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
               at java.lang.Thread.run(Thread.java:595)
              


              • 4. Re: Problem by jndi-lookup from Tomcat to JBoss
                thomas2008ch

                In the console I got followings. Seems it has problem with the jndi-lookup.

                INFO: Deploying web application archive TestXDocletWeb.war
                javax.naming.NameNotFoundException: Name Tiger is not bound in this Context
                 at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
                 at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
                 at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
                 at javax.naming.InitialContext.lookup(InitialContext.java:351)
                 at com.zoo.TigerUtil.lookupHome(TigerUtil.java:22)
                 at com.zoo.TigerUtil.getHome(TigerUtil.java:42)
                 at org.apache.jsp.index_jsp._jspService(index_jsp.java:77)
                 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
                .java:393)
                 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
                20)
                 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
                 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                icationFilterChain.java:290)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                ilterChain.java:206)
                 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                alve.java:233)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                alve.java:175)
                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                ava:128)
                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                ava:102)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                ve.java:109)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                a:263)
                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
                :844)
                 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
                ss(Http11Protocol.java:584)
                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
                7)
                 at java.lang.Thread.run(Thread.java:595)
                
                


                • 5. Re: Problem by jndi-lookup from Tomcat to JBoss
                  thomas2008ch

                  In the Global JNDI Namespace I see followings:

                  Global JNDI Namespace
                  ...
                  +- Tiger (proxy: $Proxy69 implements interface com.zoo.TigerHome,interface javax.ejb.Handle)
                  ...
                  ...
                   +- local (class: org.jnp.interfaces.NamingContext)
                   | +- Tiger@33422146 (proxy: $Proxy67 implements interface com.zoo.TigerLocalHome)
                  ...
                  ...
                  


                  • 6. Re: Problem by jndi-lookup from Tomcat to JBoss
                    thomas2008ch

                    Ok, I solved the problem. I make the same error again as last time. :-)

                    I have to use the environment by JNDI-lookup as follow:

                    ...
                    com.zoo.TigerHome home = com.zoo.TigerUtil.getHome(props);
                    ...

                    • 7. Re: Problem by jndi-lookup from Tomcat to JBoss
                      jaikiran

                       

                      "thomas2008ch" wrote:
                      Ok, I solved the problem. I make the same error again as last time. :-)



                      :)