Object serialization and class transport
Hi.
I lost my day to this problem. Don't even know if I can solve it, so you're my only hope, people.
I have a RMI server which accepts serialized objects of an interface. Jar file that makes up this server contains _ONLY_ this interface, and there isn't any implementations in the server classpath.
In the other corner is the other piece of software which knows the implementation class intimately (together with that common interface) and would like to transfer an object of that class to the RMI server. It first sends URL of the .jar which is the codebase of that class to the server, and then serializes object in an byte array, and then uses RMI to transfer it to the server. Transferring object directly is failing because server complains through RemoteException that it cannot load intimate class for the object, even if he knows for the common interface, so thats why I use intermediate byte array. On the other hand, I've read that client which invokes RM holds handle to the object that was sent over through method parameters, which I'd like to avoid.
Now, server uses URL and URLClassLoader to link intimate class to the VM, and this works perfectly. I can use reflection to instantiate new objects of that class, call their methods locally and do stuff over at server's side.
What I don't understand is why I cannot de-serialize the object that I've sent over through byte array, which is of that same class. When I use ObjectInputStream to read byte array to an object, it just throws out ClassNotFoundException.
On some other (forum) thread someone suggested that (application's) thread's context classloader should be set to the same one which loaded the class, and I've done it, but its not working. Liar ;-)
It really puzzles me why I cannot deserialize the object when class is loaded and everything else is working.
I'm sorry for not posting any code and using non-defined artifact's names, but we have a very strict policy of code ownership at my firm.
Please help if you can.
Thanks.

