Mantis - Hessian
Viewing Issue Advanced Details
3655 minor always 08-28-09 08:51 07-29-19 13:54
ferg  
ferg  
normal  
closed 4.0.1  
fixed  
none    
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:

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)
...


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">
    <init-param>
      <api-class>foo.HessianTest</api-class>
      <service-class>foo.HessianTestImpl</service-class>
    </init-param>
  </servlet-mapping>

Test case:
    HessianProxyFactory hessianProxyFactory = new HessianProxyFactory();
    // Workaround for http://bugs.caucho.com/view.php?id=3634 [^]
    hessianProxyFactory.setSerializerFactory(new SerializerFactory() {
      protected Deserializer loadDeserializer(Class cl) throws HessianProtocolException {
        if (InputStream.class.isAssignableFrom(cl))
          return new InputStreamDeserializer();
        else
          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;
      sb.append(digit);
      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());
    }

Output:
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

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:2391)
    at com.caucho.hessian.io.Hessian2Input.readBuffer(Hessian2Input.java:2689)
    at com.caucho.hessian.io.Hessian2Input.read(Hessian2Input.java:2661)
    at com.caucho.hessian.io.Hessian2Input.read(Hessian2Input.java:2603)
    at com.caucho.hessian.io.Hessian2Input$ReadInputStream.read(Hessian2Input.java:2785)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at java.io.BufferedReader.fill(BufferedReader.java:136)
    at java.io.BufferedReader.readLine(BufferedReader.java:299)
    at java.io.BufferedReader.readLine(BufferedReader.java:362)
    at se.exder.HessianInputStreamTest.testHessianTest(HessianInputStreamTest.java:80)
...

 </Mattias>

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

Notes
(0004196)
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.
(0004545)
stefanthurnherr   
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.
(0004686)
fabdouglas   
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?
(0004869)
selikoff   
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.
(0005058)
Holy   
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
(0005379)
selikoff   
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/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.

(0006909)
tiendat   
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?

Best
Tien Dat
(0006910)
ferg   
07-29-19 13:54   
hessian/34c1