Stateful Session bean serialization problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ravi_Kandasamy
Posted On:   Monday, December 31, 2001 02:01 PM

I am developing a stateful session bean in VAJ 3.5, the state of which i am maintaining in the HttpSession by obtaining a serialized ID of the Remote interface class's reference. I have two static methods which help serialize and deserialize my EJBObject. The two methods are as follows: public static String getId(EJBObject session) { ByteArrayOutputStream fo = null; try { javax.ejb.Handle handle = session.getHandle(); fo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(fo); so.writeObject(handle); so.flush(); so.close(); } catch (Exception e) { } return new String(fo.toByteArray(   More>>


I am developing a stateful session bean in VAJ 3.5, the state of which i am maintaining in the HttpSession by obtaining a serialized ID of the Remote interface class's reference. I have two static methods which help serialize and deserialize my EJBObject. The two methods are as follows:


public static String getId(EJBObject session) {

ByteArrayOutputStream fo = null;

try {

javax.ejb.Handle handle = session.getHandle();

fo = new ByteArrayOutputStream();

ObjectOutputStream so = new ObjectOutputStream(fo);

so.writeObject(handle);

so.flush();

so.close();

} catch (Exception e) { }

return new String(fo.toByteArray());

}




My other method to deserialize the String is as follows:

public static EJBObject getService(String id) {


try {

byte[] bytes = id.getBytes();

InputStream io = new ByteArrayInputStream(bytes);

ObjectInputStream os = new ObjectInputStream(io);

javax.ejb.Handle handle = (javax.ejb.Handle) os.readObject();

EJBObject obj= handle.getEJBObject();

return obj;

} catch (Exception e) {}

}



I am testing the above methods in my business delegate as below:


public void setPrimaryClient(ClientModel model) {

SFSBTest session = null, session1 = null;

try {

session = (SFSBTest) getSessionObject();

session.setPrimaryClient(model);

EJBObject obj =
com.nph.EJBHomeFactory.getService(

com.nph.EJBHomeFactory.getId(session));

session1=(SFSBTest)javax.rmi.PortableRemoteObject.narrow(obj,SFSBTestRemote);

ClientModel mod1 = session1.getPrimaryClient();

} catch (java.rmi.RemoteException e) {
}
}


While executing the above method, I am able to execute the remote interface method setPrimaryClient(), able to serialize the EJBObject to a string and then obtain a reference to the EJBObject without any problems. But at the point when i invoke a business method like getPrimaryClient(), I get a java.rmi.NoSuchObjectException. The strange thing is the object reference numbers before and after serialization do not match. I don't know if this is normal. I am using VAJ 3.5 EE with the default PNS.


Have anybody encountered such a problem before. Any help is appreciated.

Thanks,

Ravi.

   <<Less
About | Sitemap | Contact