6 Replies Latest reply on Jul 29, 2008 1:52 PM by Bentley Johnson

    ClassCastException when using jndi lookup in simple project

    Bentley Johnson Newbie

      Using version 5.0.0 CR1 a simple project was setup including an EJB3 bean project, and a web project within an ear.

      The bean project contained 1 local stateless bean.

      The web project contained a servlet which attempted to lookup the bean using the standard jndi lookup.

      When calling the lookup, the object is properly returned, but the interface is not set on the proxy and a ClassCastException is thrown. Debugging the proxy shows an inner object of the proxy has the proper interface, but is not exposed.

      The JNDI TreeView shows the proxy and the interface.

      This was working fine in 5.0.0 beta4.

      Is there a configuration change needed with the CR1 release?

      public interface Foo {
      
       String doFoo();
      }


      @Stateless
      @Local(Foo.class)
      public class Bar implements Foo {
       @Override
       public String doFoo() {
       return "Hello";
       }
      
      }


      public class Lookup extends HttpServlet {
      
       @Override
       protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
       IOException {
      
       try {
       Object obj = new InitialContext().lookup("jbosstest-ear/" + Bar.class.getSimpleName() + "/local");
       Foo foo = (Foo) obj;
       System.out.println(foo.doFoo());
       }
       catch (NamingException e) {
       e.printStackTrace();
       }
       }
      }


      java.lang.ClassCastException: $Proxy128 cannot be cast to Foo
       at Lookup.doGet(Lookup.java:26)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:183)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:90)
       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:96)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       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:325)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:619)


      +- jbosstest-ear (class: org.jnp.interfaces.NamingContext)
       | +- Bar (class: org.jnp.interfaces.NamingContext)
       | | +- local (proxy: $Proxy206 implements interface org.jboss.ejb3.proxy.JBossProxy,interface Foo)