jersey
  1. jersey
  2. JERSEY-2106

InputStream is empty in MessageBodyReader.readFrom

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: 2.4
    • Component/s: None
    • Labels:
      None

      Description

      I have an entity provider defined as:

          @Override
          public MyObject readFrom(Class<MyObject> type,
                  Type type1,
                  Annotation[] antns,
                  MediaType mt, MultivaluedMap<String, String> mm,
                  InputStream in) throws IOException, WebApplicationException {
              MyObject mo = new MyObject();
              JsonParser parser = Json.createParser(in);
              while (parser.hasNext()) {
                // . . .
              }    
              return mo;
          }
      

      Complete code at:

      https://github.com/arun-gupta/javaee7-samples/blob/master/jaxrs/readerwriter-json/src/main/java/org/javaee7/jaxrs/readerwriter/json/MyReader.java

      The InputStream receives correct data on GlassFish 4 but is empty on GlassFish 4.0.1 b03. This was reported at twitter this morning at:

      https://twitter.com/sunil_gulabani/status/381009958952648704

      A similar sample (https://github.com/arun-gupta/javaee7-samples/tree/master/jaxrs/readerwriter) that is reading the stream as ObjectInputStream seem to work fine.

        Activity

        Hide
        Libor Kramolis added a comment -

        I am not able to reproduce empty input stream. When I run your example the MyReader.readFrom returns correctly instance of MyObject in any runtime environment I used. Resource method MyResource.echoObject always returns instance.

        So the issue I found is in MyWritter.writeTo - JsonGenerator used to generate JSON does not write any byte in GF4.0.1-b03. I found out it contains javax.jsonp v1.0.2 and GF4.0 and last GF4.0.1-b04-* nightbuild contains javax.jsonp v1.0.3.

        It means problem is in JSONP or other library it uses to generate JSON writing to OutputStream. (Writing to Writer works fine.)

        Show
        Libor Kramolis added a comment - I am not able to reproduce empty input stream. When I run your example the MyReader.readFrom returns correctly instance of MyObject in any runtime environment I used. Resource method MyResource.echoObject always returns instance. So the issue I found is in MyWritter.writeTo - JsonGenerator used to generate JSON does not write any byte in GF4.0.1-b03. I found out it contains javax.jsonp v1.0.2 and GF4.0 and last GF4.0.1-b04-* nightbuild contains javax.jsonp v1.0.3. It means problem is in JSONP or other library it uses to generate JSON writing to OutputStream. (Writing to Writer works fine.)
        Hide
        Libor Kramolis added a comment -

        Identified as JSONP issue that is already fixed in last GF night builds.

        Show
        Libor Kramolis added a comment - Identified as JSONP issue that is already fixed in last GF night builds.
        Hide
        sunil_gulabani added a comment -

        Yes I also think the issue is related with Json API and GF 4.0.1-b03.

        Show
        sunil_gulabani added a comment - Yes I also think the issue is related with Json API and GF 4.0.1-b03.
        Hide
        arungupta added a comment -

        Can you assign this to Jitu then ?

        Show
        arungupta added a comment - Can you assign this to Jitu then ?
        Hide
        Libor Kramolis added a comment -

        I think this is issue JSONP-18 that was fixed in JSONP 1.0.3. I am not sure it is necessary move this issue report to JSONP project.

        Show
        Libor Kramolis added a comment - I think this is issue JSONP-18 that was fixed in JSONP 1.0.3. I am not sure it is necessary move this issue report to JSONP project.

          People

          • Assignee:
            Libor Kramolis
            Reporter:
            arungupta
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 4 hours
              4h