Skip to content

Clarification about Response.readEntity(XXX) #736

@NicoNes

Description

@NicoNes

According to the javadoc of:

  • Response.readEntity(Class)
  • Response.readEntity(javax.ws.rs.core.GenericType)
  • Response.readEntity(Class, Annotation [])
  • Response.readEntity(javax.ws.rs.core.GenericType, Annotation [])
  1. those methods are supposed to close the original entity input stream (unless the supplied type is input stream) and then cache the result for subsequent retrievals via Response.getEntity().
    So it clearly means that those methods MUST not close() the response itself, else subsequent retrievals via Response.getEntity() will always end up with IllegalStateException being thrown.
    Instead, only the underlying input stream should be closed.

  2. Subsequent call to one of those methods MUST throw an IllegalStateException if the original entity input stream has already been fully consumed without buffering the entity data prior consuming.

In other words:

Message s1 = r.readEntity(Message.class);
System.out.println(s1.toString());
System.out.println(r.getEntity());      => should not throw no exception
s1 = r.readEntity(Message.class);                     => should throw an IllegalStateException

Is my understanding right for those 2 points ? because it seems that many implementation (https://issues.jboss.org/browse/RESTEASY-2112) including the RI (Jersey) does not behave as exepected for point 1.
If my understanding is wrong what is the intented behavior of those methods ?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions