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

[jsr339-experts] Re: Unexpected Response.fromResponse result

From: Sergey Beryozkin <sberyozkin_at_talend.com>
Date: Mon, 6 Aug 2012 23:21:12 +0300

On 06/08/12 23:10, 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'm just wondering what is the user implementing the server filer
supposed to do when say a new header needs to be added...Why the user
should make sure about calling this buffer() method, as far as I recall,
this method should throw IllegalArgumentException on the server side



> 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


-- 
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com