[JERSEY-847] Entity of the response will always be empty when resource methods return type is java.io.Reader. Created: 02/Dec/11  Updated: 10/Sep/15  Resolved: 06/Nov/13

Status: Closed
Project: jersey
Component/s: core
Affects Version/s: 1.8
Fix Version/s: 1.18

Type: Bug Priority: Major
Reporter: hosamu Assignee: Michal Gajdos
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: 0 minutes
Time Spent: 1 hour
Original Estimate: 3 hours

Issue Links:
Duplicate
is duplicated by JERSEY-1632 Return type for the resource method i... Closed

 Description   

Entity of the response will always be empty when resource methods return type is java.io.Reader.

Resource class/method
@Path("hello")
public class Hello {
    @GET
    public java.io.Reader sayHello() {
        return new java.io.StringReader("Hello, World!");
    }
}

As follows, I think, need to calling the OutputStreamWriter#flush().

com.sun.jersey.core.impl.provider.entity.ReaderProvider
    public void writeTo(
            Reader t, 
            Class<?> type, 
            Type genericType, 
            Annotation annotations[], 
            MediaType mediaType, 
            MultivaluedMap<String, Object> httpHeaders,
            OutputStream entityStream) throws IOException {
|       OutputStreamWriter out = null;
        try {
|           out = new OutputStreamWriter(entityStream, getCharset(mediaType));
|           writeTo(t, out);
        } finally {
|           if (out != null)
|               out.flush();
            t.close();
        }
    }


 Comments   
Comment by Jakub Podlesak [ 04/Feb/13 ]

This is already fixed in Jersey 2, where the out.flush() call comes right after the writeTo method invocation. We need to port the fix back to Jersey 1.

Comment by Jakub Podlesak [ 04/Feb/13 ]

Should be fixed in 1.18.
2.0 codebase has already been fixed.

Generated at Sat Dec 03 09:36:31 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.