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