1

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

David K
  • 1,296
  • 18
  • 39
  • the question is a wall of text, and not clear at all. Please repharse it. It is a interesting question since getting ObjectInStream working over TCP can get tricky. Just edit your question for more clarity. – Siddharth Jul 31 '12 at 13:45
  • @Siddharth: I rephrased the question to hopefully make it more understandable. If you still have questions, please let me know what is confusing. – David K Jul 31 '12 at 16:30

1 Answers1

0

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.

Siddharth
  • 9,349
  • 16
  • 86
  • 148
  • I dont know why you are doing Message msg = (Message) messageIn.getObject(); You have your messageIn object, thats it.. you are done. – Siddharth Aug 01 '12 at 13:23
  • messageIn is a SignedObject, which contains a Message object. I created the Message class so that all of my communications follow a standard format. When sending a communication with a signature, it is easiest to enclose it in a SignedObject, but to retrieve my unsigned communication I must use SignedObject.getObject(). – David K Aug 01 '12 at 14:07
  • Here's the Javadoc for [SignedObject](http://docs.oracle.com/javase/1.4.2/docs/api/java/security/SignedObject.html) – David K Aug 01 '12 at 14:22