Skip to main content

Java RMI - java.io.NotSerializableException when trying to fetch class over RMI

1 reply [Last post]
vzvz
Offline
Joined: 2012-08-18
Points: 0

Good afternoon,

I am trying to learn Java RMI.
I found a tutorial at http://www.javacoffeebreak.com/articles/javarmi/javarmi.html which worked fine.

It works fine with methods returning BigInteger.
I added one method to server that should fetch a class to client.

But when trying to run the option 3 - Get TestClass from the client, I get this exception:

Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: TestClass
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:191)
at PowerServiceServer_Stub.get(Unknown Source)
at PowerServiceClient.main(PowerServiceClient.java:85)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: TestClass
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:324)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:173)
... 2 more
Caused by: java.io.NotSerializableException: TestClass
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:292)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:332)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)

I am running server with this command:
java -Djava.security.policy=./java.policy PowerServiceServer
And the client with this one:
java -Djava.security.policy=./java.policy PowerServiceClient localhost

The java.policy file is also included in the attached rmitest.tar.gz.

We already tried to find out the problem with a friend, but we were not successful..

Thank you in advance for help.

AttachmentSize
rmitest.tar_.gz4.58 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vzvz
Offline
Joined: 2012-08-18
Points: 0

OK, I found it out.

The class that I wanted to transfer - named TestClass in the attached sources - was not implementing Serializable interface. When I added "implements Serializable" to the class definition, it works fine now. I spent this afternoon by trying to find this out :)