I am sending an object encased in a Message object encase in a SignedObject over a TCP connection using an ObjectInputStream. Here's the basic code:
Send
Object data = someObject;
ObjectOutputStream = new ObjectOutputStream(socket.getOutputStream());
Message newMsg = new Message(data);
out.writeObject(security.signObject(newMsg,privKey));
Receive
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Object line = in.readObject();
SignedObject messageIn = (SignedObject) line;
Message msg = (Message) messageIn.getObject();
The Message class is a basic class with only fields and no methods. One of the fields is Object Message.data, which in this case contains either siena.Filter or siena.Notification. When I call SignedObject.getObject(), I get an InvalidObjectException. The stack trace is below.
java.io.InvalidObjectException: siena.SENPInvalidFormat
at siena.Filter.readObject(Filter.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.security.SignedObject.getObject(Unknown Source)
The code for the message transfer is correct. It works for numerous other cases with other classes, and even with other versions of the same class. It is not working for a specific version of siena.Filter and siena.Notification.
I can see that the readObject() method of the class being sent (siena.Filter or siena.Notification) is being called, but I don't know if this is supposed to be happening or not. I know that an exception is being thrown within the siena method, which I'm guessing is causing the InvalidObjectException.
So the question is, is the problem that siena.class.readObject() is throwing an exception and is not written properly, or is the problem that siena.class.readObject() is being called at all? If the latter, how would I go about fixing that?
Thanks, David
Why do you just type cast what you are getting from your InputObjectStream to the type of object that you are passing ? Once you get readObject, just typecast it to your SingledObject, should work ? Sorry again I am unable to completely understand. Its better you put in some code here.