jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: [jax-rs-spec users] Response.getEntity vs Response.readEntity

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Fri, 17 Aug 2012 12:21:56 +0200

On Aug 16, 2012, at 6:21 PM, Sergey Beryozkin <sberyozkin_at_talend.com> wrote:

> Response.readEntity docs say:
>
> "A non-null message instance returned from this method will be cached for subsequent retrievals via getEntity(). Unless the supplied entity type is an input stream, this method automatically closes the consumed response entity stream if it is not buffered. In case he entity input stream has been buffered, it will be reset when the method returns to enable subsequent invocations of the readEntity(...) methods on this response. "
>
> Suppose we have Response containing unconsumed InputStream.
>
> I expect that initial Response.getEntity() returns a non-null Object which is the same as the internal unconsumed InputStream:
>
> assertTrue(Response.getEntity() instanceof InputStream);
>
> Next, we do
>
> Response.bufferEntity();
> // assuming a buffered entity is kept in ByteArrayInputStream
> assertTrue(Response.getEntity() instanceof InputStream);
>
> Book book = Response.readEntity(Book.class);
>
> At this stage, what Response.getEntity() is supposed to return ?
> Is it Book ? I think this is what the docs say but I'm not sure it is right...

Yes. Response.readEntity() javadoc: "A non-null message instance returned from this method will be cached for subsequent retrievals via getEntity()"

Marek

>
> Thanks, Sergey
>
>
>
>