4 Replies Latest reply on Oct 6, 2005 1:34 PM by rgrantitt

    Failing JNDI Lookup from Servlet to Stateless Session bean

    andrigtmiller

      I have been building a prototype application using the JBoss IDE 1.5 M2, and am having a problem where the servlet cannot lookup the Stateless Session bean. I have looked over all the code and deployment descriptors and cannot find anything that explains the problem. Here is the exception I am getting:

      javax.servlet.ServletException: Lookup of java:/comp/env/ejb/Order failed
      at services.web.NewOrderServlet.init(NewOrderServlet.java:52)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:816)

      note

      The exception is not really helpful and there is nothing else in the JBoss logs. Here is my servlet code for the JNDI lookup:

      public void init(ServletConfig config) throws ServletException {
       super.init(config);
      
       try {
       Context context = new InitialContext();
       Object reference = context.lookup("java:/comp/env/ejb/Order");
       home = (OrderHome) PortableRemoteObject.narrow(reference, OrderHome.class);
       } catch (Exception e) {
       throw new ServletException("Lookup of java:/comp/env/ejb/Order failed");
       }
      
       }


      Here are the deployment descriptors as well:

      <?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_2.dtd">
      
      <jboss-web>
      
       <!-- Resource Environment References -->
       <!--
       For additional resouce-env-ref tags add a merge file called jbossweb-resource-env-ref.xml
       -->
      
       <!-- Resource references -->
       <!--
       For additional resouce-ref tags add a merge file called jbossweb-resource-ref.xml
       -->
      
       <!-- EJB References -->
       <!--
       For additional ejb-ref tags add a merge file called jbossweb-ejb-ref.xml
       -->
       <ejb-ref>
       <ejb-ref-name>ejb/Order</ejb-ref-name>
       <jndi-name>ejb/Order</jndi-name>
       </ejb-ref>
      
       <!-- EJB Local References -->
      
       <!--
       For additional ejb-local-ref tags add a merge file called jbossweb-ejb-local-ref.xml
       -->
      
      </jboss-web>
      


      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      
      <ejb-jar >
      
       <description>[CDATA[No Description.]]</description>
       <display-name>Generated by XDoclet</display-name>
      
       <enterprise-beans>
      
       <!-- Session Beans -->
       <session >
       <description>[CDATA[This Order Service can create new Orders]]</description>
       <display-name>Order Service</display-name>
      
       <ejb-name>Order</ejb-name>
      
       <home>services.interfaces.OrderHome</home>
       <remote>services.interfaces.Order</remote>
       <ejb-class>services.ejb.OrderBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
      
       </session>
      
       <!--
       To add session beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called session-beans.xml that contains
       the <session></session> markup for those beans.
       -->
      
       <!-- Entity Beans -->
       <!--
       To add entity beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called entity-beans.xml that contains
       the <entity></entity> markup for those beans.
       -->
      
       <!-- Message Driven Beans -->
       <!--
       To add message driven beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called message-driven-beans.xml that contains
       the <message-driven></message-driven> markup for those beans.
       -->
      
       </enterprise-beans>
      
       <!-- Relationships -->
      
       <!-- Assembly Descriptor -->
       <assembly-descriptor >
       <!--
       To add additional assembly descriptor info here, add a file to your
       XDoclet merge directory called assembly-descriptor.xml that contains
       the <assembly-descriptor></assembly-descriptor> markup.
       -->
      
       <!-- finder permissions -->
      
       <!-- transactions -->
      
       <!-- finder transactions -->
       </assembly-descriptor>
      
      </ejb-jar>


      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
      
      <jboss>
      
       <enterprise-beans>
      
       <!--
       To add beans that you have deployment descriptor info for, add
       a file to your XDoclet merge directory called jboss-beans.xml that contains
       the <session></session>, <entity></entity> and <message-driven></message-driven>
       markup for those beans.
       -->
      
       <session>
       <ejb-name>Order</ejb-name>
       <jndi-name>ejb/Order</jndi-name>
      
       <method-attributes>
       </method-attributes>
       </session>


      And ideas would be helpful.

      Thanks.

        • 1. Re: Failing JNDI Lookup from Servlet to Stateless Session be
          gennady1974

          I just have got the same problem using JBossIDE 1.4
          Tried to use remote or local interfaces, the problem looks the same.
          The context.lookup call returns me a valid (<>null) object,
          but later I can't cast it to my ejb's home interface.

          // this is running well
          Object oRef = context.lookup("ejb/StockExchange");

          // can't cast
          m_oHome = (StockExchangeHome) PortableRemoteObject.narrow(oRef, StockExchangeHome.class);


          Any ideas?

          Thank you,
          Gen

          • 2. Re: Failing JNDI Lookup from Servlet to Stateless Session be
            gennady1974

            P.S.

            Jboss 4.02, JDK 1.4.9

            • 3. Re: Failing JNDI Lookup from Servlet to Stateless Session be
              gennady1974

              My problem is related to packaging: see 'classCastException while casting ejb Home's proxy'.

              • 4. Re: Failing JNDI Lookup from Servlet to Stateless Session be
                rgrantitt

                I am seeing something very similar to this, however it is while running JBoss as a cluster. If I run Jboss as a stand alone server I can connect to my EJBs, however if I Cluster Jboss 4.0.2 using jboss cache 1.2.3 I have a problem with jndi.

                [LogonAction] ERROR: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
                javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
                at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1302)
                at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1382)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
                at javax.naming.InitialContext.lookup(InitialContext.java:347)

                It is as though I cannot use my org.jboss.ha.jndi.HANamingService.

                Any ideas?