2 Replies Latest reply on Sep 26, 2007 5:09 AM by ritesh udapudi

    EJB3: StandardWrapper.Throwable

    ritesh udapudi Newbie

      I am new to EJB developmet, so i started off by writing a simple session bean which just returns a string. And I have a servlet which displays the returned string.

      I followed a tutorial and came up with the following files.

      TestStateless.java
      package com.j3ltd.test.ejbs;
      import javax.ejb.Remote;

      @Remote
      public interface TestStateless {
      public String testBean();
      }


      TestStatelessBean.java
      package com.j3ltd.test.ejbs;

      import javax.ejb.Stateless;
      import com.j3ltd.test.ejbs.TestStateless;


      public @Stateless class TestStatelessBean implements TestStateless {

      public String testBean() {
      return "the server returned this string";
      }
      }


      TestStatelessEJBServlet.java

      package com.j3ltd.test.web;
      import javax.servlet.*;
      import javax.servlet.http.*;
      import javax.naming.*;
      import java.io.*;
      import com.j3ltd.test.ejbs.*;

      public class TestStatelessEJBServlet extends HttpServlet {
      private TestStatelessBean statelessBean;

      public void init() {
      try {
      InitialContext ctx = new InitialContext();
      statelessBean = (TestStatelessBean) ctx.lookup("TestStatelessBean/remote");

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

      public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      doGet(req, resp);
      }

      public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
      PrintWriter writer = resp.getWriter();
      writer.write("The stateless bean returned this string: " + statelessBean.testBean());
      }
      }


      I have bundled the web.xml and the servlet in a .war file and the bean interface and implementation in an .ejb3 file along with jndi.properties file.

      when i try accessing the servlet the following is the error. I think theres a problem with the binding of the bean, and the lookup is failing. Im using JBoss 4.2.1 and eclipse 3.1
      Can someone help me wid this? the stack trace is

      01:48:32,055 INFO [Server] JBoss (MX MicroKernel) [4.2.1.GA (build: SVNTag=JBoss_4_2_1_GA date=200707131605)] Started in 32s:968ms
      01:49:24,169 ERROR [[/TestInstallation]] StandardWrapper.Throwable
      java.lang.ClassCastException: $Proxy70
      at com.j3ltd.test.web.TestStatelessEJBServlet.init(TestStatelessEJBServlet.java:18)
      at javax.servlet.GenericServlet.init(GenericServlet.java:212)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Unknown Source)
      01:49:24,169 ERROR [[TestStatelessEJBServlet]] Allocate exception for servlet TestStatelessEJBServlet
      java.lang.ClassCastException: $Proxy70
      at com.j3ltd.test.web.TestStatelessEJBServlet.init(TestStatelessEJBServlet.java:18)
      at javax.servlet.GenericServlet.init(GenericServlet.java:212)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Unknown Source)