users@jersey.java.net

Re: [Jersey] Jersey Client API suggestion

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 31 Mar 2009 17:28:36 +0200

Hi Patrick,

Did you see my response to a previous email you sent, on the 24th
March, on a similar subject?

http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users+Using+annotated+POJOs+to+build+client+request#query
:list%3Anet.java.dev.jersey.users%20Using%20annotated%20POJOs%20to
%20build%20client%20request+page:1+mid:fm5talthbic6bbow+state:results


In you example what is the representation (request entity body) sent
in the post request?

The problem i have with your proposed solution is it mixes the request
entity 'w' with the request URI. What if you were going to do the same
thing with a GET request, for example, that does not send request
entities ?

I think the right approach is to consider the separate pieces of
functionality like creating a URI path from a bean and that URI can be
used to create a WebResource and then that WebResource can be reused.
Then steps may be combined for eas of use, for example:

   BeanUri bu = new BeanUri();
   // set state on bu

   Client c = ....
   c.resource(bu);

might be equivalent to:

   BeanUri bu = new BeanUri();
   // set state on bu

   Client c = ....
   URI u = c.createUri(bu);
   c.resource(bu);

Paul.

On Mar 31, 2009, at 5:05 PM, Patrick Sansoucy wrote:

> Hello,
>
> After a couple of exchanges with Jakub Podlesak on the Twitter
> RESTfull example, he suggested I post my suggestion here ...
>
> Basically, it consists of using pojos to build the path and it's
> content instead of building from path and map.
> A high level example would look like this:
>
> /* this would build the resulting /
> widget&id=[myid]&color=[mycolor]&type=[mytype] */
> @Path("/widget&id={id}&color={color}&type={type}")
> public class Widget{
> protected String id;
> protected String color;
> protected String type;
>
> public @PathParam("id") String getId() {
> return this.id;
> }
>
> public void setId(String aId) {
> this.id = aId;
> }
>
> public @PathParam("color") String getColor() {
> return this.color;
> }
>
> public void setColor(String aColor) {
> this.color = aColor;
> }
>
> public @PathParam("type") String getType() {
> return this.type;
> }
>
> public void setType(String aType) {
> this.type = aType;
> }
> }
>
> public class WidgetClient {
> ...
>
> public WidgetBean getWidget(String aId, String aColor, String
> aType) {
> Widget w = new Widget();
> w.setId(aId);
> w.setColor(aColor);
> w.setType(aType);
> return
> wr.accept(MediaType.APPLICATION_XML_TYPE).post(WidgetBean.class, w);
> }
> ...
> }
>
> I was wondering if such mechanism could be implemented or was
> planned (or maybe it does already exist and I am not aware of it )
> because it would greatly enrich and ease the use of the client API ...
> Thank you for your time ...
> Patrick S.