users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Unexpected Response.fromResponse result

From: Bill Burke <bburke_at_redhat.com>
Date: Tue, 07 Aug 2012 06:15:17 -0700

I don't understand what the problem is. Javadoc is just saying that if
the underlying entity is an InputStream, then the Response copy has a
reference to that InputStream. You probalby should buffer it because
you will get an error if two different Response objects referencing the
same InputStream call readEntity().

On 8/6/2012 1:10 PM, Sergey Beryozkin wrote:
> In JAX-RS 1.1 I was seeing an easy to understand Response.fromResponse
> output. For example,
>
> Response r = Response.entity("Hello").build();
> Response r2 = Response.fromResponse(r);
> assertSame("Hello", r2.getEntity());
>
> Note that 'r' contains a String, not 'InputStream'.
> 'Response.entity("Hello").build()' is executed on the server, where as
> 'Response.fromResponse(r)' is a follow up operation executed in a
> response filter.
>
> In 2.0 I'm seeing 'Response.fromResponse(r)' losing the original
> 'String', and after checking the java docs I'm seeing:
>
> "Note that if the entity is backed by an un-consumed input stream, the
> reference to the stream is copied. In such case make sure to buffer the
> entity stream of the original response instance before passing it to
> this method."
>
> I think it's an API bug. The assumption is made there that the Response
> entity is kept as InputStream - which is an implementation detail of
> Response. I've been saying that all this buffer() stuff is out of scope
> of Response but failed to get anyone convinced.
>
> For the very least, the javadocs quoted above should further clarify
> that it only applies to the client side where it is reasonable to expect
> Response contains InputStream originally.
>
> Any comments ?
> Sergey

-- 
Bill Burke
JBoss, a division of Red Hat