title: Is executing a JAX-RS 2.0 Invocation twice supported by the spec, and if not, is this a spec flaw?
body: <p>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.</p>
  
  <p>I do note that page 121 of RESTful Java with JAX-RS 2.0 by Bill Burke (<a href="https://books.google.com/books?id=wzkYAgAAQBAJ&amp;pg=PA121" rel="nofollow">https://books.google.com/books?id=wzkYAgAAQBAJ&amp;pg=PA121</a>) 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.</p>
  
  <p>However, 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 request and then subsequent executions would not provide an accurate ClientRequestContext.  I could be misreading this, though.</p>
  
  <p>Assuming 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.</p>
  
  <p>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.</p>
  
  <p>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?</p>