jersey
  1. jersey
  2. JERSEY-847

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

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.18
    • Component/s: core
    • Labels:
      None

      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();
              }
          }
      

        Issue Links

          Activity

          Hide
          Jakub Podlesak added a comment -

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

          Show
          Jakub Podlesak added a comment - Should be fixed in 1.18. 2.0 codebase has already been fixed.
          Hide
          Jakub Podlesak added a comment -

          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.

          Show
          Jakub Podlesak added a comment - 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.

            People

            • Assignee:
              Michal Gajdos
              Reporter:
              hosamu
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 3 hours
                3h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour Time Not Required
                1h