简体   繁体   English

java.io.StreamCorruptedException:块数据的意外结束-在不同的JVM之间进行通信时

[英]java.io.StreamCorruptedException: unexpected end of block data - when communicating between defferent JVMs

I have a EJB client and a EJB2 server which runs on a JBoss 4 server . 我有一个EJB客户端和一个在JBoss 4 server上运行的EJB2 JBoss 4 server It was working fine for same JVM version(1.6). 对于相同的JVM版本(1.6),它工作正常。 Then I upgrade client JVM to 1.7(but compiler version is 1.6) while keeping server JVM as the same(1.6). 然后,我将客户端JVM升级到1.7(但编译器版本为1.6),同时保持服务器JVM不变(1.6)。 java.io.StreamCorruptedException: unexpected end of block data error occurs in client side if server method returns an object or throws exeption. java.io.StreamCorruptedException: unexpected end of block data如果服务器方法返回一个对象或抛出异常,则客户端发生java.io.StreamCorruptedException: unexpected end of block data错误。 But server side functionality execute without any error. 但是服务器端功能可以正常执行。 This happens for all methods calls in this server module. 此服务器模块中的所有方法调用都会发生这种情况。 But there are some other server modules which works without any exception. 但是还有其他一些服务器模块可以正常工作。 Any idea on this issue? 对这个问题有什么想法吗?

Edit:- If return type is newly created class it works fine 编辑:-如果返回类型是新创建的类,则可以正常工作

I had this problem and did like this right now: 我遇到了这个问题,现在就这样:

import org.apache.commons.io.IOUtils;

    byte[] bytes;
    try {
        bytes = IOUtils.toByteArray(uploadedFile.getInputstream());
        image.setContent(bytes);
        imageService.save(image);
    } catch (IOException ex) {
        ...
    }

You most likely use Java Serialization for the communication between client and server. 您很可能将Java序列化用于客户端和服务器之间的通信。

For Java Serialization to work correctly, both client and server need to have compatible version of class file (I also believe Java did not guarantee the serialization type to be compatible between versions, but I can't find any documentation for that now). 为了使Java序列化正常工作,客户端和服务器都必须具有兼容的类文件版本(我也相信Java不保证序列化类型在版本之间是兼容的,但现在找不到任何文档)。

When you have different versions of Java, then quite likely some class might have different structure (example would be Throwable (superclass of Exception ), which has new field suppressedExceptions in Java7). 如果您有不同版本的Java,那么很可能一些类可能有不同的结构(例如是Throwable的(超Exception ),它具有新的领域suppressedExceptions在Java7)。 Normally, the serialization tries to throw meaningful exception for that, but in some cases, it might fail to do so and only throws the StreamCorruptedException . 通常,序列化会为此尝试引发有意义的异常,但是在某些情况下,序列化可能无法这样做,而只会引发StreamCorruptedException

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

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