hessian协议从rpc服务获取inputStream流下载文件的方式,出现异常 java.io.IOException: stream is closed
2017-05-23 12:50
2361 查看
在写文件服务的时候,用hessian协议从rpc服务获取inputStream流下载文件的方式,出现异常
java.io.IOException: stream is closed
at sun.net.www.http.ChunkedInputStream.ensureOpen(ChunkedInputStream.java:151)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:646)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2446)
at com.caucho.hessian.io.Hessian2Input.readBuffer(Hessian2Input.java:2689)
at com.caucho.hessian.io.Hessian2Input.read(Hessian2Input.java:2635)
at com.caucho.hessian.io.Hessian2Input$ReadInputStream.read(Hessian2Input.java:2785)
...
发现是由于hessian 4.0版本后的一个bug导致,链接http://bugs.caucho.com/view.php?id=3655和http://blog.csdn.net/whk010/article/details/52758131有介绍。
自2009年开始就有工程师向caucho组织提过此bug但是没有在以后的版本修复(比较纳闷,以后琢磨他们为什么不改吧)。
工程师也提出了解决方案:
You just need to update src/com/caucho/hessian/client/HessianProxy.java and add:
if (value instanceof InputStream) {
value = new ResultInputStream(conn, is, in, (InputStream) value);
is = null;
conn = null;
}
After line:
Object value = in.readReply(method.getReturnType());
I've verified it as solving the issue.
但是此方案要重新打包,然后用自己的hessian包,这样就不利于以后包的更新。所以就尝试了把inputStream流放在类中传递等方法,但是都不奏效。也不想用byte[]的方式返回文件内容,这样效率低也不安全。
所以没办法,还是解压了hessian-4.0.7.jar然后添加修改代码,重新打包然后发布包<dependency>
<groupId>com.xxxxxx.hessian</groupId>
<artifactId>hessian</artifactId>
<version>4.0.7-SNAPSHOT</version>
</dependency>
然后文件服务工程写死依赖这个版本的hessian包解决此问题。
(ps:还是等caucho修改此bug以后发布了最新的包,依赖最新的靠谱些,要不然以后工程中的其他包要用到最新的hessian包可就麻烦了。不过不知道要等到什么时候,哈哈)
java.io.IOException: stream is closed
at sun.net.www.http.ChunkedInputStream.ensureOpen(ChunkedInputStream.java:151)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:646)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2446)
at com.caucho.hessian.io.Hessian2Input.readBuffer(Hessian2Input.java:2689)
at com.caucho.hessian.io.Hessian2Input.read(Hessian2Input.java:2635)
at com.caucho.hessian.io.Hessian2Input$ReadInputStream.read(Hessian2Input.java:2785)
...
发现是由于hessian 4.0版本后的一个bug导致,链接http://bugs.caucho.com/view.php?id=3655和http://blog.csdn.net/whk010/article/details/52758131有介绍。
自2009年开始就有工程师向caucho组织提过此bug但是没有在以后的版本修复(比较纳闷,以后琢磨他们为什么不改吧)。
工程师也提出了解决方案:
You just need to update src/com/caucho/hessian/client/HessianProxy.java and add:
if (value instanceof InputStream) {
value = new ResultInputStream(conn, is, in, (InputStream) value);
is = null;
conn = null;
}
After line:
Object value = in.readReply(method.getReturnType());
I've verified it as solving the issue.
但是此方案要重新打包,然后用自己的hessian包,这样就不利于以后包的更新。所以就尝试了把inputStream流放在类中传递等方法,但是都不奏效。也不想用byte[]的方式返回文件内容,这样效率低也不安全。
所以没办法,还是解压了hessian-4.0.7.jar然后添加修改代码,重新打包然后发布包<dependency>
<groupId>com.xxxxxx.hessian</groupId>
<artifactId>hessian</artifactId>
<version>4.0.7-SNAPSHOT</version>
</dependency>
然后文件服务工程写死依赖这个版本的hessian包解决此问题。
(ps:还是等caucho修改此bug以后发布了最新的包,依赖最新的靠谱些,要不然以后工程中的其他包要用到最新的hessian包可就麻烦了。不过不知道要等到什么时候,哈哈)
相关文章推荐
- 阿里巴巴dubbo处理文件上传下载 java.io.IOException: stream is closed
- javaIE下载文件中取消下载出现ClientAbortException: java.io.IOException异常
- java.io.IOException: Attempted read from closed stream. 异常,解决
- java后台调用SOE时,报异常java.io.IOException: Attempted read from closed stream
- java.io.IOException: The stream is closed
- java.io.IOException:stream closed 异常的原因及处理
- java多线程运行结果写入文件错误java.io.IOException: Stream closed
- Android断点下载时异常:java.io.IOException: unexpected end of stream,请问该怎么解决
- java.io.IOException:stream closed 异常的原因及处理
- java.io.IOException:stream closed 异常的原因及处理
- 【Java】异常 java.io.IOException: Stream closed 的解决办法
- java.io.IOException:stream closed 异常的原因及处理
- java.io.IOException:stream closed 异常的原因及处理
- java.io.IOException:stream closed 异常的原因及处理
- 使用Dubbo服务出现java.io.IOException: invalid constant type: 18异常解决办法
- java.io.IOException: Attempted read from closed stream.
- struts2文件下载 出现Can not find a java.io.InputStream with the name的错误
- java.io.IOException: BufferedInputStream is closed
- java.io.IOException: Attempted read on closed stream.可能原因及解决方案
- apache-karaf-3.0.0发布features,出现"java.io.IOException: Error resolving artifact"异常解决