1 Reply Latest reply on Oct 14, 2005 3:29 AM by Vijaypal Singh

    java.lang.ClassCastException:While Lookup

    Vijaypal Singh Newbie

      Hi Everybody,
      I'am creating a example where my .ear file contains the following structure,
      1.A war file(for login page anf dashboard)
      2.A .par file(including 1 stateless and 3 entity bean and a persistence.xml)
      my example works excellent when i run it from a standalone client from eclipse.but when I try to access it from the web client it produces following error.
      Exception in Helper.lookup() java.lang.ClassCastException: cannot assign
      instance of org.jboss.proxy.ejb.EJBMetaDataImpl to field org.jboss.ejb3.session.BaseSessionRemotePr
      oxy.ejbMetaData of type javax.ejb.EJBMetaData in instance of org.jboss.ejb3.stateless.StatelessRemot
      eProxy

      My Code is as following
      /** HELPER CLASS ***/
      import java.util.Properties;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;


      public class Helper {
      /**
      * RETURN INITIAL CONTEXT FOR THE JNDI LOOKUP.
      * @return
      */
      private InitialContext getInitialContext(){
      InitialContext ctx=null;
      Properties env = new Properties();
      env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      env.put("java.naming.provider.url", "jnp://nsg-sd36:1099");
      env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      try{
      ctx = new InitialContext(env);
      }catch(NamingException n){
      System.out.println("Naming Exception "+n);
      }
      System.out.println(" Returning Initial Context "+ctx+" From Helper.getInitialContext()");
      return ctx;
      }
      public Object lookup(String JNDIName){
      System.out.println("Inside Lookup "+JNDIName);
      Object obj=null;
      try {
      InitialContext ctx = (InitialContext)getInitialContext();
      System.out.println(" 1. "+ctx);
      obj = ctx.lookup(JNDIName);
      }catch(Exception e){
      System.out.println("Exception in Helper.lookup() "+e);
      }
      System.out.println("Returning "+obj+" From Helper.lookup()");
      return obj;
      }


      }

      /*** CLIENT CODE ***/
      public boolean validateUser(String userName,String password){
      System.out.println("5.Inside LoginAction.validateUser()");
      System.out.println("6.VALUE RECEIVED IN VALIDATE-USER USER-NAME ="+userName+" AND PASSWORD = "+password);
      boolean flag=false;
      ApplicationUser applicationUser=null;
      Helper helper = new Helper();
      applicationUser=(ApplicationUser)helper.lookup(ApplicationUser.class.getName());
      try{
      flag = applicationUser.login(userName,password);
      }catch(Exception e){
      System.out.println("Exception occured"+e);
      }
      System.out.println("7.VALUE BEING RETURNED FROM VALIDATE-USER = "+flag);
      return flag;
      }

      /*** BEAN CODE ****/
      public boolean login(String userName, String password) {
      boolean retval=false;
      java.util.List list = manager.createQuery("select count(user)from User user where user.userName = '"+userName+"' and user.password = '"+password+"' ").getResultList();
      if(list!=null && list.get(0)!=null&& list.get(0).equals("")){
      System.out.println("ApplicationUserBean.login value received from query = "+list.get(0));
      if(list.get(0).equals("0"))
      retval= false;
      else
      retval= true;
      }
      return retval;
      }

      Thanks in anticipation,
      Vijaypal Singh

        • 1. Re: java.lang.ClassCastException:While Lookup
          Vijaypal Singh Newbie

           

          "vijaypalsingh" wrote:
          Hi Everybody,
          I'am creating a example using ejb3 and jboss 4.0.2 where my .ear file contains the following structure,
          1.A war file(for login page anf dashboard)
          2.A .par file(including 1 stateless and 3 entity bean and a persistence.xml)
          my example works excellent when i run it from a standalone client from eclipse.but when I try to access it from the web client it produces following error.
          Exception in Helper.lookup() java.lang.ClassCastException: cannot assign
          instance of org.jboss.proxy.ejb.EJBMetaDataImpl to field org.jboss.ejb3.session.BaseSessionRemotePr
          oxy.ejbMetaData of type javax.ejb.EJBMetaData in instance of org.jboss.ejb3.stateless.StatelessRemot
          eProxy

          My Code is as following
          /** HELPER CLASS ***/
          import java.util.Properties;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;


          public class Helper {
          /**
          * RETURN INITIAL CONTEXT FOR THE JNDI LOOKUP.
          * @return
          */
          private InitialContext getInitialContext(){
          InitialContext ctx=null;
          Properties env = new Properties();
          env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
          env.put("java.naming.provider.url", "jnp://nsg-sd36:1099");
          env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
          try{
          ctx = new InitialContext(env);
          }catch(NamingException n){
          System.out.println("Naming Exception "+n);
          }
          System.out.println(" Returning Initial Context "+ctx+" From Helper.getInitialContext()");
          return ctx;
          }
          public Object lookup(String JNDIName){
          System.out.println("Inside Lookup "+JNDIName);
          Object obj=null;
          try {
          InitialContext ctx = (InitialContext)getInitialContext();
          System.out.println(" 1. "+ctx);
          obj = ctx.lookup(JNDIName);
          }catch(Exception e){
          System.out.println("Exception in Helper.lookup() "+e);
          }
          System.out.println("Returning "+obj+" From Helper.lookup()");
          return obj;
          }


          }

          /*** CLIENT CODE ***/
          public boolean validateUser(String userName,String password){
          System.out.println("5.Inside LoginAction.validateUser()");
          System.out.println("6.VALUE RECEIVED IN VALIDATE-USER USER-NAME ="+userName+" AND PASSWORD = "+password);
          boolean flag=false;
          ApplicationUser applicationUser=null;
          Helper helper = new Helper();
          applicationUser=(ApplicationUser)helper.lookup(ApplicationUser.class.getName());
          try{
          flag = applicationUser.login(userName,password);
          }catch(Exception e){
          System.out.println("Exception occured"+e);
          }
          System.out.println("7.VALUE BEING RETURNED FROM VALIDATE-USER = "+flag);
          return flag;
          }

          /*** BEAN CODE ****/
          public boolean login(String userName, String password) {
          boolean retval=false;
          java.util.List list = manager.createQuery("select count(user)from User user where user.userName = '"+userName+"' and user.password = '"+password+"' ").getResultList();
          if(list!=null && list.get(0)!=null&& list.get(0).equals("")){
          System.out.println("ApplicationUserBean.login value received from query = "+list.get(0));
          if(list.get(0).equals("0"))
          retval= false;
          else
          retval= true;
          }
          return retval;
          }

          Thanks in anticipation,
          Vijaypal Singh