2 Replies Latest reply on Apr 15, 2009 8:08 AM by areyyyyy

    java.lang.ClassCastException: $Proxy78 cannot be cast to com

      Hi,
      I got the following error when i tried to lookup on statefull session bean.

      java.lang.ClassCastException: $Proxy78 cannot be cast to com.vs.uhome.model.session.LoginSession
      com.vs.uhome.model.util.PropertyUtil.getLoginSession(PropertyUtil.java:239)
      com.vs.uhome.view.serv.mainServ.onLogin(mainServ.java:101)
      com.vs.uhome.view.serv.mainServ.doPost(mainServ.java:79)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

      Here i m giving statefull session bean

      @Stateful(name = "uhomeSession")
      public class LoginSessionBean implements LoginSession {
      @PersistenceContext(unitName = "Model")
      private EntityManager em;
      private PropertyLogger pl;
      private Ruser sessionUser;
      private FinderMethods fm;

      public void logon(String userEmail, String password, boolean encrypted)
      throws UnknownException, WarningException {
      pl.write("Entered logon(String, String, boolean)", 1,
      "DefaultSessionBean", "logon");
      if ((userEmail == null) || userEmail.matches("^\\s*$")) {
      throw new WarningException(new CatalogHelper("UHOME_002002", 1,
      "DefaultSession", "logon"));
      }
      if (password == null) {
      password = "";
      }
      if (encrypted) {
      logon(userEmail, password);
      } else {
      String ecPasswd = PropertyUtil.encodeStr(password + userEmail);
      logon(userEmail, ecPasswd);
      }
      pl.write("Leaving logon(String, String, boolean)", 1,

      }
      }


      And i m doing lookup like this


      public static LoginSession getLoginSession() throws UnknownException, WarningException {
      LoginSession ls;
      Context ctx;
      try {
      ctx = getInitialContext();
      } catch (WarningException we) {
      throw we;
      } catch (NamingException ne) {
      throw new UnknownException (new CatalogHelper("UHOME_900035", ne.getMessage(), ne, "PropertyUtil", "getLoginSession"));
      }
      try {
      ls = (LoginSession)ctx.lookup("uhomeSession/remote");
      return ls;
      } catch (NamingException ne) {
      throw new UnknownException (new CatalogHelper("UHOME_900036", new Object[]{"LoginSession", ne.getMessage()}, ne, "PropertyUtil", "getLoginSession"));
      }
      }



      and i got the JNDI view like this
      +- uhomeSession (class: org.jnp.interfaces.NamingContext)
      | +- remote (class: java.lang.Object)
      | +- remoteStatefulProxyFactory (proxy: $Proxy79 implements interface org.jboss.ejb3.ProxyFactory)

      Can you please tell what is the problem. How to resolve this problem?
      Thanks in advance!

        • 1. Re: java.lang.ClassCastException: $Proxy78 cannot be cast to
          peterj

          I don't like the looks of the JNDI view entries - the "remote" node should be of a proxy for LoginSession. You did remember to add the @Remote annotation ot LoginSession, didn't you?

          By the way, please use the code tag when posting code, and do a preview to check the formatting before submitting.

          • 2. Re: java.lang.ClassCastException: $Proxy78 cannot be cast to

            Hi,

            Thanks for ur reply.
            Here i am providing remote interface and stateful session beans:



            @Stateful(name = "uhomeSession")
            @Remote( { LoginSession.class })
            public class LoginSessionBean implements LoginSession {
            @PersistenceContext(unitName = "Model")
            private EntityManager em;
            private PropertyLogger pl;
            private Ruser sessionUser;
            private FinderMethods fm;

            public LoginSessionBean() throws UnknownException, WarningException {
            pl = PropertyLogger.getInstance();
            fm = new FinderMethods();
            pl.write("Leaving LoginSessionBean constructor", 1, "LoginSessionBean",
            "LoginSessionBean");
            }

            ... some more methods
            }


            @Remote
            public interface LoginSession {
            Object mergeEntity(Object entity);
            void checkSessionUser(String methodName) throws WarningException;
            void logout();
            ... some more methods
            }



            and i am working with server JBOSS4.2.3GA.

            Still i am getting same exception mentioned earlier.

            and JNDI VIEW is
            +- uhome (class: org.jnp.interfaces.NamingContext)
            | +- DefaultSessionBean (class: org.jnp.interfaces.NamingContext)
            | | +- remote (proxy: $Proxy96 implements interface com.vs.uhome.model.session.DefaultSession,interface org.jboss.ejb3.JBossProxy)
            | +- uhomeSession (class: org.jnp.interfaces.NamingContext)
            | | +- remote (class: java.lang.Object)
            | | +- remoteStatefulProxyFactory (proxy: $Proxy65 implements interface org.jboss.ejb3.ProxyFactory)


            I have deployed both stateless (DefaultSessionBean) and stateful (LoginSessionBean).I could call stateless from my servlet but i could not call statefull session beans.

            and to mention i have deployed web files in war and all ejb files as jar inside uhome.ear file with application.xml file given below

            <!DOCTYPE application PUBLIC "-//Sun Microsystems,
            Inc.//DTD J2EE Application 1.2//EN"
            "http://java.sun.com/j2ee/dtds/application_1_2.dtd">

            <display-name>Uhome Application</display-name>


            <web-uri>ViewController.war</web-uri>
            <context-root>/ViewController</context-root>



            Model.jar



            Please tell me why stateful session beans remote node did not implement the proxy of loginsession? and what jndi string should i use to lookup for the login session?
            Thanks