Mantis - Hessian
Viewing Issue Advanced Details
3655 minor always 08-28-09 08:51 07-29-19 13:54
closed 4.0.1  
none 4.0.63  
0003655: Hessian InputStream result is closed
(rep by Mattias Jiderhamn)
After upgrading from Resin/Hessian 3.1 to 4.0.1 we have a problem
returning InputStream from Hessian calls.
I get this exception while trying to read the stream on the client: stream is closed

I created a small testcase which just sends the output of a
Hessian2Output to a Hessian2Input and in that case, InputStream works fine.

The proxy is created using Springs HessianProxyFactoryBean.

Any tips on how to debug this???


Both client and server is using Hessian included in Resin 4.0.1. Here is a detailed test case (without Spring):

Service interface:
public interface HessianTest {
  InputStream testString(String input);

Service implementation:
public class HessianTestImpl implements HessianTest {
  public InputStream testString(String s) {
    return new ByteArrayInputStream(s.getBytes());

Service configuration; web.xml:
  <servlet-mapping url-pattern="/hessian/test" servlet-class="com.caucho.hessian.server.HessianServlet">

Test case:
    HessianProxyFactory hessianProxyFactory = new HessianProxyFactory();
    // Workaround for [^]
    hessianProxyFactory.setSerializerFactory(new SerializerFactory() {
      protected Deserializer loadDeserializer(Class cl) throws HessianProtocolException {
        if (InputStream.class.isAssignableFrom(cl))
          return new InputStreamDeserializer();
          return super.loadDeserializer(cl);
    HessianTest hessianTest = (HessianTest) hessianProxyFactory.create(HessianTest.class, "http://localhost/hessian/test"); [^]
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < 512; i++) {
      final int digit = (i % 10) + 1;
      System.out.println("No of chars: " + sb.length());
      InputStream is = hessianTest.testString(sb.toString());
      BufferedReader br = new BufferedReader(new InputStreamReader(is));
      assertEquals(sb.toString(), br.readLine());

No of chars: 1
No of chars: 2
No of chars: 3
No of chars: 4
No of chars: 5
No of chars: 6
No of chars: 7
No of chars: 8
No of chars: 9
No of chars: 11
No of chars: 12
No of chars: 13
No of chars: 14
No of chars: 15
No of chars: 16
No of chars: 17
No of chars: 18
No of chars: 19 stream is closed
    at sun.nio.cs.StreamDecoder.readBytes(
    at sun.nio.cs.StreamDecoder.implRead(
    at se.exder.HessianInputStreamTest.testHessianTest(


 Hessian_3000655.patch [^] (571 bytes) 08-28-09 09:46

Peter Dettman   
08-28-09 09:49   
I was able to reproduce Mattias' issue, and tracked the problem down to HessianProxy (see attached patch). The call to http.disconnect in the finally block of the invoke method was causing the reply to be truncated. I have copied the handling for Hessian 1 'InputStream' replies and it appears to fix the problem.
04-26-10 03:46   
Hi Hessian team

Any chance that this gets fixed in the next official minor/major release? I just hit the same bug using resin-hessian 4.0.3 on the server side, and hessian-4.0.3 on the client side.
07-29-10 14:17   
This bug exists in 4.0.7, and the attached patch works very well for this version.

Any change to get it in 4.0.8?
12-09-10 12:39   
Is there a reason this bug has not been resolved? The solution works perfectly. Without the fix transferring/downloading files is broken in Hessian 4.
02-15-11 07:26   
Hello, is there a chance to get this patch to next release? And is there a time plan for this release? Thx
07-18-11 12:12   
Could someone please include this fix in the next release? I'd update the SVN myself, but I'm not familiar with the repository.

You just need to update src/com/caucho/hessian/client/ 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.

07-27-19 05:37   
Dear experts,

I have been able to reproduced this issue in Hessian v4.0.38.

Just wonder if this issue was fixed in the newest version?

Tien Dat
07-29-19 13:54