3 Replies Latest reply on Oct 18, 2005 3:25 AM by Martin Heinemann

    Whats wrong with this stateful session beans?

    Martin Heinemann Newbie

      Hi,
      this thing here gets me upset.
      I have a simple stateful session bean which is looked up by a remote client.
      During the lookup i got an exception:

      First the Bean:

      package musicstore.session;
      
      import java.util.ArrayList;
      import java.util.Collection;
      
      import javax.annotation.Resource;
      import javax.ejb.PostConstruct;
      import javax.ejb.Remote;
      import javax.ejb.SessionContext;
      import javax.ejb.Stateful;
      
      import musicstore.entity.MusicCD;
      
      
      
      @Remote(Order.class)
      public @Stateful class OrderBean implements Order{
      
       /**
       *
       */
       private static final long serialVersionUID = 1L;
      
       @Resource SessionContext sessionContext;
      
       public Collection <MusicCD> orderList;
      
       private String customerName = "uups, i forgot to set a name";
      
      
      
      // @Resource
      // protected InitialContext iniCtx;
      
       @PostConstruct
       public void initialize() {
       this.orderList = new ArrayList<MusicCD>();
       }
      
       /**
       * Adds a cd to the orderlist
       * @param cd
       */
       public void addCd(MusicCD cd) {
       this.orderList.add(cd);
       }
      
       /**
       * Removes a cd from the orderlist
       * @param cd
       */
       public void removeCD(MusicCD cd) {
       this.orderList.remove(cd);
       }
      
       /**
       * Returns a complete arary of all cds in the orderlist
       *
       * @return
       */
       public Collection<MusicCD> getAll() {
       return this.orderList;
       }
      
       /**
       * Sets the name of the customer for the order
       * @param name
       */
       public void setCustomerName(String name) {
       this.customerName = name;
       }
      
       /**
       * "Submits" the order and returns a string containing the order
       * @return
       */
       public String submit() {
       // submit the data to a message queue
       // TODO
       String orderstr = new String();
       orderstr = "New Order: \n Customer: "+this.customerName+"\n";
       // Append all cd in the queue
       int count = 1;
       for (MusicCD cd : this.orderList) {
       orderstr = orderstr + count +". " + cd + "\n";
       count++;
       }
      
       return orderstr;
      
       }
      
      }
      

      The remote interface
      package musicstore.session;
      
      import java.util.Collection;
      import musicstore.entity.MusicCD;
      
      public interface Order {
      
       /**
       * Adds a cd to the orderlist
       * @param cd
       */
       public void addCd(MusicCD cd);
      
       /**
       * Removes a cd from the orderlist
       * @param cd
       */
       public void removeCD(MusicCD cd);
      
       /**
       * Returns a complete arary of all cds in the orderlist
       *
       * @return
       */
       public Collection<MusicCD> getAll();
      
       /**
       * Sets the name of the customer for the order
       * @param name
       */
       public void setCustomerName(String name);
      
       /**
       * Submits the order and returns a string containing the order
       */
       public String submit();
      
      }
      


      I think this must be without any mistakes. Correct me if its not :-/

      And now the client:

      package musicstore.clients;
      
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.List;
      
      import javax.annotation.EJB;
      import javax.naming.InitialContext;
      
      import musicstore.entity.MusicCD;
      import musicstore.session.Inventory;
      import musicstore.session.Order;
      import musicstore.session.OrderBean;
      
      
      public class MusicStoreClient {
      
       private Order order;
       public void doinit() {
       try {
       System.out.println("Name: " + Order.class.getName());
       order = (Order) ctx.lookup(Order.class.getName());
       System.out.println(order.submit());
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      
       public static void main (String[] args) {
       MusicStoreClient msc = new MusicStoreClient();
       msc.doinit();
       }
      
      
      }


      Everytime i call teh client i got an exception like this one:
      Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/jboss/invocation/Invoker;
       at java.lang.Class.getDeclaredFields0(Native Method)
       at java.lang.Class.privateGetDeclaredFields(Class.java:2232)
       at java.lang.Class.getDeclaredField(Class.java:1852)
       at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1555)
       at java.io.ObjectStreamClass.access$600(ObjectStreamClass.java:47)
       at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:381)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:373)
       at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:268)
       at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:504)
       at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1546)
       at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:107)
       at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1753)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1711)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
       at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
       at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:73)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:242)
       at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:112)
       at org.jboss.remoting.Client.invoke(Client.java:226)
       at org.jboss.remoting.Client.invoke(Client.java:189)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:34)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
       at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:46)
       at $Proxy0.createProxy(Unknown Source)
       at org.jboss.ejb3.JndiProxyFactory.getObjectInstance(JndiProxyFactory.java:32)
       at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
       at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1110)
       at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1127)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:690)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at musicstore.clients.MusicStoreClient.doinit(MusicStoreClient.java:32)
       at musicstore.clients.MusicStoreClient.main(MusicStoreClient.java:223)
      


      When i turn the Bean to a stateless SessionBean, no Problem.
      Is there a special way to look up stateful SessionBeans which i do not know?
      Please help, this is annoying very much.
      Thanks

      martin