Hi Bill
On 26/08/11 23:24, Bill Burke wrote:
>
>
> On 8/26/11 5:06 PM, Sergey Beryozkin wrote:
>> Thus we have a flow for making perfect HTTP invocation, always ending at
>> Target.
>> And we can always do, when needed
>> Invocation.prepare(target).get().invoke();
>>
>
> Can you write some code to get a better idea what you're talking about?
>
Have a look here:
http://java.net/projects/jax-rs-spec/sources/git/content/src/examples/src/main/java/jaxrs/examples/client/BasicExamples.java?rev=64934b368c20c86a6d3e2a9c85948ade93760296
showing some basic examples in the prev revision from Marek,
check commonFluentUseCases().
What I propose is to drop an explicit link between Target and Invocation
in the form of Target.prepare() and move it to Invocation itself.
So
client.target("
http://examples.jaxrs.com/").path("123").accept("text/plain").get();
shows the regular HTTP request. When we want to do a single request like
this one, there's no need to rely on a command pattern.
If we do need a command pattern then we are talking about batch
invocations and this means we are after building a collection of
requests - we don't need batch invocations for single requests. But this
requirement is orthogonal/next-level one to the idea
of making a plain HTTP request - hence the pressure on the API in order
to accommodate both ideas in a single flow.
So having Target.prepare() moved to a static method of Invocation will
let us cleanly deal with this extra requirement whenever it's needed.
If you look at
http://java.net/projects/jax-rs-spec/sources/git/content/src/jax-rs-api/src/main/java/javax/ws/rs/client/Invocation.java?rev=64934b368c20c86a6d3e2a9c85948ade93760296
then imagine it having
public static Invocation.PrepareBuilder prepare(Target t);
For example,
1. Create and initialized Target:
Target t =
client.target("
http://examples.jaxrs.com/").path("123").accept("text/plain");
// usually, next we well do t.get();
2. Need an invocable entity ?
List<Invocation> invocations=...;
invocations.add(Invocation.prepare(t).get());
Invocation.prepare(t).get() is a flow on its own and its initialized
when it's really needed to be able to do invoke() or submit() in a
generic fashion...In all other cases - just target.get()/post()/etc;
I reckon that may provide for a reasonable compromise,
users won't need to type yet another factory method "request()" when
building a Target for most cases but still API will ship a utility
Invocation class which can facilitate dealing with batched requests...
Cheers, Sergey