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

[jsr339-experts] Re: [Client API] Refactoring Link and Invocation

From: Bill Burke <bburke_at_redhat.com>
Date: Thu, 07 Jul 2011 14:20:50 -0400

On 7/7/11 11:44 AM, Sergey Beryozkin wrote:
> Santiago Pericas-Geertsen wrote:
>> On Jul 7, 2011, at 11:15 AM, Sergey Beryozkin wrote:
>>
>>>>> Link link =
>>>>> client.link("http://jaxrs.examples.org/jaxrsApplication/customers/{id}");
>>>>>
>>>>>
>>>>> link.pathParam("id", 123).get();
>>>>> link.pathParam("id", 124).get();
>>>> This is not the same example, you forgot the query param which is
>>>> used in the first and _not_ the second invocation. This is why the
>>>> separation between Link and Invocation make sense. See other
>>>> examples in Bill's message.
>>> Are you saying that in the current API you have to create a new
>>> Invocation instance per every query ?
>>
>> Implicitly, yes. This is because an Invocation can be further
>> configured and should be independent of the original Link so that it
>> can be re-used. There are several reasons for this --another example
>> is async calls that may be queued and don't want to reference a Link
>> that may be updated by another thread before it's used.
>>
>>> Does it really make sense ?
>>>
>>>>> link.pathParam("id", 123).query("bar", "foo").get();
>>> link.query("bar", null);
>>>>> link.pathParam("id", 124).get();
>>
>> This isn't simpler and is error prone for developers as they may need
>> to reset the internal state of a Link by using multiple calls before
>> re-using it.
>>
>>> works, UriBuilder does support resetting queries this way and I see
>>> no reasons HttpRequest can't. We can also repeat client.link()
>>> factory call when needed,
>>> Besides, I think it's not a very realistic example but I don't think
>>> it's an issue anyway.
>>
>> There are many use cases in which a base Link is defined and then
>> slightly tweaked by adding different params or paths to carry out
>> multiple invocations.
>
> That is OK, I think I've done many clarfications already suggesting that
> the same issue persists with the current approach
>
> client.request().get()
> client.request().get()
>
> or
>
> Invocation inv = client.request()
> inv.get();
> inv.get();
>
> Lets have Link simplified and Client using it to create new Invocations
> as opposed to Links also acting as factories - we won;t loose a bit but
> only improve the code and get get() and friends finalizing the chain
>

Sergey, client.request(link) is no different than
client.request(uribuilder) IMO.

You will also want to use Link interface as it current exists, for link
headers and the hypermedia framework.

so, you could do:

HttpResponse res = client.request(...).get();

res = res.getLinkHeader("edit").request().post();

or, with a hypermedia API like Restfulie:

Customer cust = client.request(...).get();
client.links(cust).getLink("edit").request().post();

With your approach of Link *NOT* being a request factory, you'd have to
interact with the Client object.


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com