1 Reply Latest reply on Dec 25, 2002 11:57 AM by Rich Coad

    NameNotFound - but I cannot tell why

    Rich Coad Newbie

      I'm trying rather desperately to get a proof-of-concept EJB
      based application together by January 2. I'm using XDoclet and JBoss 3.0.3 with Jetty on Mac OS X (I've also tried JBoss 3.0.4 with Tomcat on OS X). (I do have Linux available if this turns out to be an OS X bug.)

      XDoclet does a great job of building the interfaces and deployment descriptors and everything appears to deploy just fine; however, when I try to access my EJB from a test servlet I get a NameNotFoundException - Role not bound. I added some debug printlns to the servlet and can see the following logged statements:

      As the EAR file is deployed I see

      10:00:29,911 DEBUG [JettyService] Linking ejb-ref: ejb/Role to JNDI name: ejb/Role

      When I run my servlet I see

      10:00:54,242 INFO [STDOUT] Binding list for java:comp/env NamingEnumeration: org.jnp.interfaces.NamingEnumerationImpl@2fec3f
      10:00:54,245 INFO [STDOUT] ejb: org.jnp.interfaces.NamingContext:org.jnp.interfaces.NamingContext@32e676
      10:00:54,247 INFO [STDOUT] security: org.jnp.interfaces.NamingContext:org.jnp.interfaces.NamingContext@388372
      10:00:54,249 INFO [STDOUT] Binding list for java:comp/env/ejb NamingEnumeration: org.jnp.interfaces.NamingEnumerationImpl@3dcbe5
      10:00:54,251 INFO [STDOUT] Role: javax.naming.LinkRef:Reference Class Name: javax.naming.LinkRef
      Type: LinkAddress
      Content: ejb/Role
      10:00:54,254 ERROR [STDERR] javax.naming.NameNotFoundException: Role not bound
      10:00:54,256 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      10:00:54,257 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      10:00:54,259 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      10:00:54,260 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      10:00:54,262 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
      10:00:54,264 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:456)
      10:00:54,266 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:440)
      10:00:54,267 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:345)
      10:00:54,269 ERROR [STDERR] at SIMSTestServlet.(SIMSTestServlet.java:37)
      10:00:54,270 ERROR [STDERR] at java.lang.Class.newInstance0(Native Method)
      10:00:54,272 ERROR [STDERR] at java.lang.Class.newInstance(Class.java:232)
      10:00:54,273 ERROR [STDERR] at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:172)
      10:00:54,275 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:281)
      10:00:54,277 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:339)
      10:00:54,278 ERROR [STDERR] at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:284)
      10:00:54,280 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:577)
      10:00:54,283 ERROR [STDERR] at org.mortbay.http.HttpContext.handle(HttpContext.java:1674)
      10:00:54,285 ERROR [STDERR] at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:544)
      10:00:54,286 ERROR [STDERR] at org.mortbay.http.HttpContext.handle(HttpContext.java:1624)
      10:00:54,296 ERROR [STDERR] at org.mortbay.http.HttpServer.service(HttpServer.java:875)
      10:00:54,298 ERROR [STDERR] at org.jboss.jetty.Jetty.service(Jetty.java:541)
      10:00:54,300 ERROR [STDERR] at org.mortbay.http.HttpConnection.service(HttpConnection.java:785)
      10:00:54,301 ERROR [STDERR] at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:935)
      10:00:54,303 ERROR [STDERR] at org.mortbay.http.HttpConnection.handle(HttpConnection.java:802)
      10:00:54,304 ERROR [STDERR] at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:200)
      10:00:54,306 ERROR [STDERR] at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:294)
      10:00:54,308 ERROR [STDERR] at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743)
      10:00:54,309 ERROR [STDERR] at java.lang.Thread.run(Thread.java:491)

      The servlet code and web.xml and jbos-web.xml are below.

      import java.io.*;
      import java.text.*;
      import java.util.*;
      import javax.servlet.*;
      import javax.servlet.http.*;
      import javax.naming.*;
      import javax.rmi.*;
      import com.scimagix.ejb.role.RoleHome;

      /**
      * My test servlet
      *
      * @author Rich Coad
      */

      public class SIMSTestServlet extends HttpServlet {

      private Context ctx;
      private RoleHome home;

      public SIMSTestServlet() throws NamingException {
      try {
      ctx = new InitialContext();

      NamingEnumeration ne = ctx.listBindings("java:comp/env");
      System.out.println("Binding list for java:comp/env NamingEnumeration: "+ne);
      while (ne.hasMore()) {
      System.out.println(ne.next());
      }

      // Context ejbCtx = ctx.lookup("java:comp/env/ejb");
      NamingEnumeration ne2 = ctx.listBindings("java:comp/env/ejb");
      System.out.println("Binding list for java:comp/env/ejb NamingEnumeration: "+ne2);
      while (ne2.hasMore()) {
      System.out.println(ne2.next());
      }
      Object obj = ctx.lookup("ejb/Role");
      System.out.println("obj is "+obj);

      home = (RoleHome) PortableRemoteObject.narrow(obj, RoleHome.class);
      System.out.println("Home is "+home);

      } catch (Exception e) {e.printStackTrace();}
      }

      public void doGet(HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException {

      response.setContentType("text/html");
      PrintWriter out = response.getWriter();

      out.println("");
      out.println("");
      out.println("Role Entity Bean");
      out.println("");
      out.println("<body bgcolor=\"white\">");

      out.println("<h1> Role Data: </h1>");
      try {
      Collection c = home.findAll();
      Iterator iterator = c.iterator();
      while (iterator.hasNext()) {
      // RoleEntity re = (RoleEntity)iterator.next();
      // out.println("Name: " + re.getName() + "");
      // out.println("Description: " + re.getDescription() + "");
      out.println(iterator.next());
      }

      } catch (Exception e) {
      out.println(e.toString());
      }
      out.println("");
      out.println("");
      }


      public void doPost(HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException
      {
      doGet(request, response);
      }
      }

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <!DOCTYPE web-app
      PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN'
      'http://java.sun.com/j2ee/dtds/web-app_2.2.dtd'>

      <web-app>
      <display-name>SIMS 2 EJB</display-name>
      SIMS 2.0 Using JBoss and EJB

      <servlet-name>SIMSTestServlet</servlet-name>
      <servlet-class>SIMSTestServlet</servlet-class>

      <servlet-mapping>
      <servlet-name>SIMSTestServlet</servlet-name>
      <url-pattern>/SIMSTest</url-pattern>
      </servlet-mapping>
      <ejb-ref>
      <ejb-ref-name>ejb/Role</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      com.scimagix.ejb.role.RoleHome
      com.scimagix.ejb.role.Role
      <ejb-link>Role</ejb-link>
      </ejb-ref>
      </web-app>

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE jboss-web
      PUBLIC '-//JBoss//DTD Web Application 2.3//EN'
      'http://www.jboss.org/j2ee/dtd/jboss-web_3_0.dtd'>

      <jboss-web>
      <ejb-ref>
      <ejb-ref-name>ejb/Role</ejb-ref-name>
      <jndi-name>ejb/Role</jndi-name>
      </ejb-ref>
      </jboss-web>

      I've tried a number of variations for the JNDI name but all yield the same result. I'm about ready to give up and watch the Two Towers and enjoy my vacation but I'm ready to give it one more try if anyone has any insight about this.

      Thanks.