users@jax-rs-spec.java.net

[jax-rs-spec users] Re: Is executing a JAX-RS 2.0 Invocation twice supported by the spec?

From: Ron Dagostino <rndgstn_at_gmail.com>
Date: Sun, 24 Jan 2016 20:25:22 -0500

Hi again, everyone. As a followup to my question, I would like to note
that page 121 of RESTful Java with JAX-RS 2.0 by Bill Burke (
https://books.google.com/books?id=wzkYAgAAQBAJ&pg=PA121) does state "[T]he
same Invocation object can be used for multiple requests. Just prebuild
your Invocation instances and reuse them as needed." But while that gives
me confidence that reusing an Invocation instance will work with RESTEasy,
I need confidence that Invocation objects can be reused in any JAX-RS 2.0
compliant implementation (we use Jersey and CXF in addition to RESTEasy).

Looking at the source code for Jersey v2.22.1, it seems to me that an
Invocation cannot reliably be reused because the ClientRequestContext is
mutable and is not copied for every execution of the Invocation instance; I
think this means it could be mutated by a filter in one reand then
subsequent executions would not provide an accurate ClientRequestContext.

On Sat, Jan 23, 2016 at 7:20 PM, <rndgstn_at_gmail.com> wrote:

> Hi everyone. I believe there is nothing in the JAX-RS 2.0 spec that
> says an instance implementing javax.ws.rs.client.Invocation MUST be
> executable multiple times, and I am looking for confirmation or
> correction on this belief. I want to be able to execute an HTTP call
> via the JAX-RS 2.0 Client APIs and have the ability to invoke the exact
> same call a second time when the first call fails in a specific way.
>
> Assuming the above is correct -- I can't execute an Invocation (via an
> invoke() or a submit() call) multiple times in a manner that is
> guaranteed to work across multiple JAX RS implementations (e.g. it must
> work in Jersey, RESTEasy, etc.) -- then the closest I think I can come
> is an instance of Invocation.Builder. Unfortunately, though,
> Invocation.Builder does not get me all the way there because it does
> not support associating a method and optionally an entity body with it.
> If I wanted to invoke a request multiple times I would at a minimum
> need the Invocation.Builder instance plus the method and optional
> entity.
>
> I am looking for a way to define a repeatable request using JAX-RS 2.0
> in a manner that is supported by the spec and that would therefore be
> compatible across implementations -- something equivalent to an
> Invocation (which unlike Invocation.Builder has the method and the
> entity body associated with it), but repeatable.
>
> I have ideas on how to get around the limitation (assuming I am correct
> and it is one), but I would prefer to not have to do that. Is this in
> fact a limitation of the JAX RS 2.0 spec?
>
> Ron
>
> PS I posted this on Stackoverflow.com as well:
>
> http://stackoverflow.com/questions/34966970/is-executing-a-jax-rs-2-0-i
> nvocation-twice-supported-by-the-spec-and-if-not-is
>