2 Replies Latest reply on May 31, 2006 7:58 AM by Stefan Arentz

    Simple lookup results in ClassCastException

    Stefan Arentz Newbie

      I'm lost. I have such an incredibly trivial piece of code and yet it is throwing an exception that you would expect the last.

      This is on 4.0.4GA with the EJB3 profile:

      @Remote
      public interface Hello {
       String sayHello();
      }
      


      @Stateless
      public class HelloBean implements Hello {
       public String sayHello() {
       return "Hallo, wereld!";
       }
      }
      


      The exception is thrown from this code from a raw Servlet's doGet() method:

      InitialContext ic = new InitialContext();
      Hello hello = (Hello) ic.lookup("MappedName-1.0-SNAPSHOT/HelloBean/remote");
      


      The exception looks like this:

      java.lang.ClassCastException: $Proxy102
       nl.arentz.stefan.mappedname.web.HelloServlet.doGet(HelloServlet.java:31)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      


      And the relevant portion of the Global JNDI namespace like this:

       +- MappedName-1.0-SNAPSHOT (class: org.jnp.interfaces.NamingContext)
       | +- HelloBean (class: org.jnp.interfaces.NamingContext)
       | | +- remote (proxy: $Proxy102 implements interface nl.arentz.stefan.mappedname.ejb.Hello,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
       +- MappedName (class: org.jnp.interfaces.NamingContext)
       | +- ejb (class: org.jnp.interfaces.NamingContext)
      


      My EAR looks like this:

       0 Wed May 31 13:42:12 CEST 2006 META-INF/
       231 Wed May 31 13:42:10 CEST 2006 META-INF/MANIFEST.MF
       3089 Wed May 31 13:42:10 CEST 2006 MappedNameEjb-1.0-SNAPSHOT.jar
       6494 Wed May 31 13:42:10 CEST 2006 MappedNameWeb-1.0-SNAPSHOT.war
       543 Wed May 31 13:42:10 CEST 2006 META-INF/application.xml
       0 Wed May 31 13:42:12 CEST 2006 META-INF/maven/
       0 Wed May 31 13:42:12 CEST 2006 META-INF/maven/nl.arentz.stefan/
       0 Wed May 31 13:42:12 CEST 2006 META-INF/maven/nl.arentz.stefan/MappedNameEar/
       1129 Tue May 30 21:14:38 CEST 2006 META-INF/maven/nl.arentz.stefan/MappedNameEar/pom.xml
       122 Wed May 31 13:42:10 CEST 2006 META-INF/maven/nl.arentz.stefan/MappedNameEar/pom.properties
      


      and the JAR looks like this:

       0 Wed May 31 13:42:08 CEST 2006 META-INF/
       231 Wed May 31 13:42:06 CEST 2006 META-INF/MANIFEST.MF
       0 Wed May 31 13:42:06 CEST 2006 nl/
       0 Wed May 31 13:42:06 CEST 2006 nl/arentz/
       0 Wed May 31 13:42:06 CEST 2006 nl/arentz/stefan/
       0 Wed May 31 13:42:06 CEST 2006 nl/arentz/stefan/mappedname/
       0 Wed May 31 13:42:06 CEST 2006 nl/arentz/stefan/mappedname/ejb/
       226 Wed May 31 13:42:06 CEST 2006 nl/arentz/stefan/mappedname/ejb/Hello.class
       538 Wed May 31 13:42:06 CEST 2006 nl/arentz/stefan/mappedname/ejb/HelloBean.class
       0 Wed May 31 13:42:08 CEST 2006 META-INF/maven/
       0 Wed May 31 13:42:08 CEST 2006 META-INF/maven/nl.arentz.stefan/
       0 Wed May 31 13:42:08 CEST 2006 META-INF/maven/nl.arentz.stefan/MappedNameEjb/
       1366 Wed May 31 13:41:30 CEST 2006 META-INF/maven/nl.arentz.stefan/MappedNameEjb/pom.xml
       122 Wed May 31 13:42:06 CEST 2006 META-INF/maven/nl.arentz.stefan/MappedNameEjb/pom.properties
      


      This is basically the stateless calculator example from the tutorial. I have no idea what I'm doing wrong.

      S.


        • 1. Re: Simple lookup results in ClassCastException
          Bill Burke Master

          you are invoking in the same VM? JBoss serializes things in JNDI going in, but not going out. You probably have duplicate remote interfaces. One copy in your war, and one in your EJB jar. You either have to remove the duplicate code or set up JNDI CallByValue so that when you do a lookup, the result is serialized.

          • 2. Re: Simple lookup results in ClassCastException
            Stefan Arentz Newbie

             

            "bill.burke@jboss.com" wrote:
            you are invoking in the same VM? JBoss serializes things in JNDI going in, but not going out. You probably have duplicate remote interfaces. One copy in your war, and one in your EJB jar. You either have to remove the duplicate code or set up JNDI CallByValue so that when you do a lookup, the result is serialized.


            You are right of course Bill.

             1527 Wed May 31 13:42:08 CEST 2006 WEB-INF/classes/nl/arentz/stefan/mappedname/web/HelloServlet.class
             3089 Wed May 31 13:42:08 CEST 2006 WEB-INF/lib/MappedNameEjb-1.0-SNAPSHOT.jar
            


            Silly me. One silent mistake in the maven pom.xml was the cause.

            S.