5 Replies Latest reply on Mar 10, 2003 9:52 AM by chrimbo

    Servlet JNDI lookup fails but EJB exists on jmx-console

    chrimbo Newbie

      I have jboss-3.0.6_tomcat-4.1.18 installed in Win2000. I have deployed an EJB successfully to JBoss (jmx-console) port 8080 :

      jboss.j2ee
      jndiName=TeamHome,service=EJB

      but when I run my servlet in JBuilder 8 (port 8086 Tomcat 4.0 Server) I cannot find the EJB :

      *****************Failed to lookup home for bean with JNDI Name: TeamHome*****************

      The bit of code in my Servlet is :

      String jndiname = "TeamHome";

      try {
      System.out.println("JNDI name : " + jndiname);
      Object tRef = ctx.lookup(jndiname);
      }
      catch (NamingException ne) {
      System.out.println("*****************Failed to lookup home for bean with JNDI Name: " + jndiname + "*****************");
      }
      catch (RemoteException re) {
      System.out.println("*****************Remote Exception******************");
      re.printStackTrace();
      }

      Are my servlets and EJBs running in different JVMs ? I thought JBoss and Tomcat were integrated ? If so, how do I configure them to run under the same JVM ? Or am I barking up the wrong tree and it's something to do with JBuilder ?

      Your help would be much appreciated, I'm tearing my hair out with this one !!

        • 1. Re: Servlet JNDI lookup fails but EJB exists on jmx-console
          Joel Vogt Master

          when it fails, what is your stacktrace?

          • 2. Re: Servlet JNDI lookup fails but EJB exists on jmx-console
            chrimbo Newbie

            Stack trace is :

            javax.naming.NameNotFoundException: Name TeamHome is not bound in this Context
            at org.apache.naming.NamingContext.lookup(NamingContext.java:811)
            at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
            at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
            at javax.naming.InitialContext.lookup(InitialContext.java:347)*****************Failed to lookup home for bean with JNDI Name: TeamHome*****************
            at wc2004.TeamAction.perform(TeamAction.java:32)
            at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1787)
            at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)
            at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
            at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
            at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
            at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
            at java.lang.Thread.run(Thread.java:536)

            So does this must mean that I need to set some properties when I get the initial context ? If so, what ?

            • 3. Re: Servlet JNDI lookup fails but EJB exists on jmx-console
              chrimbo Newbie

              B the way I also get this looking at the jmx-console :

              Ejb Module: file%/C%/jboss-3.0.6_tomcat-4.1.18/server/default/deploy/teamEJB1.jar
              java:comp namespace of the Team bean:
              +- env (class: org.jnp.interfaces.NamingContext)
              | +- jdbc (class: org.jnp.interfaces.NamingContext)
              | | +- DefaultDS[link -> DefaultDS] (class: javax.naming.LinkRef)

              also, I am getting my initial context with the following code :

              try {
              ctx = new javax.naming.InitialContext();
              NamingEnumeration items = ctx.list("");
              while (items.hasMore()) {
              System.out.println("Listing all in context...");
              System.out.println(items.next().toString());
              }
              }
              catch (NamingException ne) {
              System.out.println("Failed to connect to JNDI service for EJB server");
              }

              and get no output from the enumeration.

              • 4. Re: Servlet JNDI lookup fails but EJB exists on jmx-console
                chrimbo Newbie

                and also ....

                Global JNDI Namespace
                +- jmx:evesham:rmi
                +- Mytab2 (proxy: $Proxy36 implements interface mytest.Mytab2Home,interface javax.ejb.Handle)
                +- jmx
                | +- rmi
                | | +- RMIAdaptor
                +- matchs (proxy: $Proxy27 implements interface wc2004.matchsHome)
                +- Mybum (proxy: $Proxy16 implements interface mybum.MybumHome,interface javax.ejb.Handle)
                +- ConnectionFactory
                +- Dtproperties (proxy: $Proxy33 implements interface mytest.DtpropertiesHome,interface javax.ejb.Handle)
                +- Abum (proxy: $Proxy13 implements interface abummer.AbumHome,interface javax.ejb.Handle)
                +- UserTransactionSessionFactory
                +- XAConnectionFactory
                +- invokers
                | +- evesham
                | | +- pooled
                | | +- jrmp
                | | +- http
                +- UserTransaction
                +- UILXAConnectionFactory
                +- RMIXAConnectionFactory
                +- TeamHome (proxy: $Proxy39 implements interface wc2004.TeamHome,interface javax.ejb.Handle)
                +- Mytab (proxy: $Proxy35 implements interface mytest.MytabHome,interface javax.ejb.Handle)

                which atleast shows my TeamHome JNDI exists in the global JNDI namespace. So why can't I find it ???

                • 5. Re: Servlet JNDI lookup fails but EJB exists on jmx-console
                  chrimbo Newbie

                  Well...I've only gone and solved it !!! Yipee !!

                  Here is what I did, changed my JNDI lookup to this as per page 47 (Naming)of the JBoss Quick Guide :

                  // Get an initial context through JNDI
                  javax.naming.Context ctx = null;
                  Properties p = new Properties();
                  p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                  p.put(Context.PROVIDER_URL, "localhost");
                  p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");

                  so we now point to the JBoss JNDI rather than the one in Tomcat I guess(?). That got me past the above problem. But then I got another one :

                  MalformedUrlException....no protocol: and

                  It turns out that the problem was that my JBuilder project was in a directory under a path in C:\Documents and Settings\.... hence the "and" in the error message. I guess Tomcat/JBoss doesn't URL encode the CLASSPATH before trying to construct a URL from it (boo !!). Anyhow, I moved my project to a directory without spaces in it and....BINGO !! It worked !

                  Does anyone know of any other way of getting around the CLASSPATH / Url problem without having to change directories ? When JBuilder starts up Tomcat, it passes the offending path in the -config option of :

                  C:\jbuilder8\jdk1.4\bin\javaw -classpath "C:\JBuilder8\thirdparty\jakarta-tomcat-4.0.6-LE-jdk14\bin\bootstrap.jar;C:\jbuilder8\jdk1.4\lib\tools.jar" -Dcatalina.home="C:/JBuilder8/thirdparty/jakarta-tomcat-4.0.6-LE-jdk14" org.apache.catalina.startup.Bootstrap -config H:\chris\jbprojects\wc2004\Tomcat\conf\server8080.xml start

                  note that my H:\chris\jbprojects\wc2004 used to be C:\Documents and Settings\....\wc2004 when I got the Url exception. Mmmmm.....any offers ??