简体   繁体   English

从SignedObject获取时发生InvalidObjectException

[英]InvalidObjectException when getting from SignedObject

I am sending an object encased in a Message object encase in a SignedObject over a TCP connection using an ObjectInputStream. 我正在使用ObjectInputStream通过TCP连接发送包含在SignedObject中的Message对象中的对象。 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. Message类是仅包含字段且没有方法的基本类。 One of the fields is Object Message.data, which in this case contains either siena.Filter or siena.Notification. 字段之一是Object Message.data,在这种情况下,它包含siena.Filter或siena.Notification。 When I call SignedObject.getObject(), I get an InvalidObjectException. 当我调用SignedObject.getObject()时,我收到一个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. 它不适用于特定版本的siena.Filter和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. 我可以看到正在发送的类(siena.Filter或siena.Notification)的readObject()方法正在被调用,但是我不知道这是否应该发生。 I know that an exception is being thrown within the siena method, which I'm guessing is causing the InvalidObjectException. 我知道siena方法内引发了异常,我猜这是导致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? 因此,问题是,siena.class.readObject()引发异常并且编写不正确的问题,还是siena.class.readObject()被完全调用的问题? 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 ? 为什么只将类型从InputObjectStream中获得的内容类型转换为要传递的对象类型? Once you get readObject, just typecast it to your SingledObject, should work ? 一旦获得readObject,只需将其类型转换为SingledObject,就可以正常工作吗? Sorry again I am unable to completely understand. 再次抱歉,我无法完全理解。 Its better you put in some code here. 最好在这里输入一些代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM