5 Replies Latest reply on Oct 26, 2006 9:00 PM by snejboss

    Exception in the Lookup Operation

    luke2006

      Hi everybody!
      I'm new at JBoss so I'm created a simply web application to begin, but I've encountered a strange Exception:
      javax.servlet.ServletException: Lookup of java:/comp/env/ failed -- java.lang.ClassCastException
      saluti.web.HolaServlet.init(HolaServlet.java:49)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      java.lang.Thread.run(Unknown Source)


      My application asks for a sentence and display it on the screen with some changes. Here is the code.
      HOLABEAN.JAVA:
      package saluti.ejb;

      import java.rmi.RemoteException;

      import javax.ejb.EJBException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;

      import javax.ejb.CreateException;

      /**
      * @ejb.bean name="Hola"
      * display-name="Name for Hola"
      * description="Description for Hola"
      * jndi-name="ejb/Hola"
      * type="Stateless"
      * view-type="remote"
      */
      public class HolaBean implements SessionBean {

      public HolaBean() {
      super();
      // TODO Auto-generated constructor stub
      }

      public void setSessionContext(SessionContext ctx)
      throws EJBException,
      RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbRemove() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbActivate() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      public void ejbPassivate() throws EJBException, RemoteException {
      // TODO Auto-generated method stub

      }

      /**
      * Default create method
      *
      * @throws CreateException
      * @ejb.create-method
      */
      public void ejbCreate() throws CreateException {
      // TODO Auto-generated method stub
      }

      /**
      * Business method
      * @ejb.interface-method view-type = "remote"
      */
      public String passer(String fraseInit) {
      fraseInit=fraseInit+" + 'Never give up!!'";
      return fraseInit;
      }
      }

      HOLASERVLET.JAVA:
      package saluti.web;

      import javax.servlet.http.HttpServlet;

      import javax.servlet.ServletException;
      import javax.servlet.ServletConfig;
      import java.io.*;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import saluti.interfaces.*;
      import javax.rmi.*;
      import java.util.*;
      import javax.naming.*;

      /**
      *
      * @web.servlet name="Hola"
      * display-name="Hola Servlet"
      * description="It's change the sentence"
      * @web.servlet-mapping url-pattern="/Hola"
      *
      * @web.ejb-ref
      * name="ejb/Hola"
      * type="Session"
      * home="saluti.interfaces.HolaHome"
      * remote="saluti.interfaces.Hola"
      * description="Reference to the Hola EJB"
      *
      * @jboss.ejb-ref-jndi
      * ref-name="ejb/Hola"
      * ndi-name="ejb/Hola"
      *
      */
      public class HolaServlet extends HttpServlet {

      private HolaHome home;

      public HolaServlet() {
      super();
      // TODO Auto-generated constructor stub
      }

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

      protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException,
      IOException {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();

      out.println("");
      out.println("E divenne...");
      out.println("");
      out.println("");
      out.println("<h1>");
      out.println("Magggggia");
      out.println("</h1>");

      try {
      Hola bean = home.create();
      String value = request.getParameter("inizio");
      String newValue = null;
      if (value!=null)
      newValue = bean.passer(value);
      bean.remove();
      out.println("");
      out.print("Ed ecco il risultato: ");
      out.println(newValue);
      out.println("");
      } catch (Exception e) {
      out.println(e.getMessage());
      e.printStackTrace(out);
      } finally {
      out.println("");
      out.close();
      }
      }//doPost

      }//HolaServlet

      INDEX.HTML:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


      Inizi di Web Service




      QUESTO E' L'INDEX DEL MIO
      PICCOLO WEB SERVICE....DA QUI...COMINCIA TUTTO........
       
      Inserisci la frase










      Thanks in advance for everything!!

      Luke

        • 1. Re: Exception in the Lookup Operation
          luke2006

          Sorry for the HTML code...the text field is named "inizio"....Thanks again!!

          • 2. Re: Exception in the Lookup Operation
            snejboss

            Hi Luke2006

            I am new to ejb. I am getting the same exception. if you come across the problem please let me know how to fix it.

            • 3. Re: Exception in the Lookup Operation
              jaikiran

              I guess the bean's remote/home interfaces are being packaged in more than one places(war and ear maybe). Have a look at:

              http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassCastExceptions

              Specifically, the jmx-console method mentioned over there.

              • 4. Re: Exception in the Lookup Operation
                snejboss

                Thanks for your reply.

                I was deploying both ear and war files in deploy directory of jboss both of remote/home interfaces are packed in these two files. so i removed war file and deployed only ear file. it contains both war and jar files. now i am getting following error. could you please have a look at it.

                javax.servlet.ServletException: Lookup of Fibo failed
                jbosstut.web.ComputeServlet.init(ComputeServlet.java:54)
                org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
                org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
                org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
                org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
                org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
                org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                java.lang.Thread.run(Thread.java:797)

                • 5. Re: Exception in the Lookup Operation
                  snejboss

                  Hi Jaikiran

                  Thanks for your help. Now my ejb is working.