0 Replies Latest reply on Mar 1, 2005 12:11 AM by Abhishek Asthana

    java.rmi.RemoteException: RemoteException occurred in server

    Abhishek Asthana Newbie

      Hi,
      I am trying to implement a simple shopping cart using stateful Session Bean.
      I am passing an item from the client and bean is supposed to add this item in an ArrayList object and return this ArrayList object.
      I don't know what's going wrong.

      I am getting this error:

      Adding item to cart
      java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
       java.rmi.ServerException: RuntimeException; nested exception is:
       java.lang.ClassCastException
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
       at sun.rmi.transport.Transport$1.run(Transport.java:148)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
       at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
       at java.lang.Thread.run(Thread.java:534)
       at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
       at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
       at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
       at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
       at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
       at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:87)
       at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
       at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
       at org.jboss.proxy.ejb.StatefulSessionInterceptor.invoke(StatefulSessionInterceptor.java:104)
       at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
       at $Proxy1.addToCart(Unknown Source)
       at cart.client.ShoppingCartClient.testBean(ShoppingCartClient.java:54)
       at cart.client.ShoppingCartClient.main(ShoppingCartClient.java:95)
      Caused by: java.rmi.ServerException: RuntimeException; nested exception is:
       java.lang.ClassCastException
       at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:360)
       at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
       at org.jboss.ejb.StatefulSessionContainer.internalInvoke(StatefulSessionContainer.java:410)
       at org.jboss.ejb.Container.invoke(Container.java:674)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
       at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:359)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
       at sun.rmi.transport.Transport$1.run(Transport.java:148)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
       at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
       at java.lang.Thread.run(Thread.java:534)
      Caused by: java.lang.ClassCastException
       at cart.sessionbean.MyCartEJBSession.getDao(MyCartEJBSession.java:44)
       at cart.sessionbean.MyCartEJBSession.addToCart(MyCartEJBSession.java:56)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.ejb.StatefulSessionContainer$ContainerInterceptor.invoke(StatefulSessionContainer.java:878)
       at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
       at org.jboss.ejb.plugins.StatefulSessionInstanceInterceptor.invoke(StatefulSessionInstanceInterceptor.java:271)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
       at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
       ... 21 more
      


      And this is the client code:
      package cart.client;
      
      import java.rmi.RemoteException;
      import java.util.Hashtable;
      import java.util.ArrayList;
      import javax.ejb.CreateException;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.*;
      import cart.sessionbean.dao.CartContents;
      import cart.sessionbean.*;
      /**
       * @author Abhishek
       *
       * To change the template for this generated type comment go to
       * Window>Preferences>Java>Code Generation>Code and Comments
       */
      public class ShoppingCartClient {
      
       CartContents cartObject=new CartContents();
       ArrayList resultCart=new ArrayList();
       int size=0;
      
       private cart.sessionbean.MyCartEJBHome getHome() throws NamingException {
       Object ref= getContext().lookup(cart.sessionbean.MyCartEJBHome.JNDI_NAME);
       MyCartEJBHome mycart =(cart.sessionbean.MyCartEJBHome)PortableRemoteObject.narrow(ref,MyCartEJBHome.class);
       return mycart;
       }
       private InitialContext getContext() throws NamingException {
       Hashtable props = new Hashtable();
      
       props.put(
       InitialContext.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
      
       InitialContext initialContext = new InitialContext(props);
       return initialContext;
       }
       public void testBean() {
      
       try {
       cart.sessionbean.MyCartEJB myBean = getHome().create(resultCart);
      
       //--------------------------------------
       //This is the place you make your calls.
       System.out.println("Adding item to cart");
       resultCart=myBean.addToCart("id001",1);
       System.out.println("Going to Sleep for 1 min ......................... " );
       Thread.sleep(60000); // sleep for 1 minute.
       //System.out.println("Reply from bean after 1min " + myBean.getMyCart());
       resultCart=myBean.getMyCart();
       size=resultCart.size();
       for(int i=0;i<size;i++)
       {
       cartObject=(CartContents)resultCart.get(i);
       System.out.println(cartObject.getItemid());
       System.out.println(cartObject.getQuantity());
      
       }
      
       System.out.println("Going to Sleep for 1 min ......................... " );
       Thread.sleep(60000);
       System.out.println("Adding item to cart");
       resultCart=myBean.addToCart("id002",2);
       resultCart=myBean.getMyCart();
       for(int i=0;i<size;i++)
       {
       cartObject=(CartContents)resultCart.get(i);
       System.out.println(cartObject.getItemid());
       System.out.println(cartObject.getQuantity());
      
       }
      
       } catch (RemoteException e) {
       e.printStackTrace();
       } catch (CreateException e) {
       e.printStackTrace();
       } catch (NamingException e) {
       e.printStackTrace();
       } catch (InterruptedException e)
       {
      
       }
       }
      
       public static void main(String[] args) {
       ShoppingCartClient test = new ShoppingCartClient();
       test.testBean();
      
       }
      }
      


      Don't know what's the error. Please help me.
      Thanks.
      Abhishek