users@jersey.java.net

Re: [Jersey] JersyClient usage pattern

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 12 Nov 2009 12:46:47 +0100

On Nov 12, 2009, at 12:26 AM, aloleary wrote:

>
> Hello..
>
> There seems to be many ways to build requests with JerseyClient
>
> I am wondering what is the best/most flexible approach for a
> detailed client
> application (that will need to do advanced requests to server...
> follow
> links etc i.e. full HATEOS to a JAX-RS/Jersey Server)
>
> I have seen the following usage patterns:
>
> a) WebResource + WebResource.Builder + WebResource.get/put ...
>
> b) ClientRequest + ClientRequest.Builder +
> Client.handle(clientRequest)
> .....
>
> Just trying to understand the relative pro's/con's with each
> approach ..
>

The recommend pattern is to utilize a). a) is a high-level abstraction
that essentially utilizes b).

If you look closely at the code you will notice a class called
PartialRequestBuilder that is used by WebResource and ClientRequest as
for building requests. Each extends that to provide terminating
methods. For WebResource those terminating methods are those of
UniformInterface. For ClientRequest the terminating method is build.

I think it may it depend on what you want to do. It is possible to
create your own abstractions using b) and PartialRequestBuilder if a)
does not suit your needs.

Certainly we can improve the hyperlinking functionality of the client.

Paul.