users@jersey.java.net

Re: [Jersey] WebResource and type method

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 07 May 2009 11:04:40 +0200

On May 7, 2009, at 10:43 AM, Alexandre Bertails wrote:

> Hi all,
>
> I have a problem with jersey-client 1.0.3.
>
> This code is ok :
>
> WebResource wr = ...
> wr.path("/
> path
> ").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class,
> form);
>
> But this one is not :
>
> WebResource wr = ...
> wr.path("/path").type(MediaType.MULTIPART_FORM_DATA_TYPE)
> wr.post(ClientResponse.class, form);
>

You need to do the following:

   WebResource wr = ...
   WebResource.Builder wrb = wr.path("/
path").type(MediaType.MULTIPART_FORM_DATA_TYPE);
   wrb.post(ClientResponse.class, form);

WebResource is immutable, state for a request is modified on the
builder returned.

A call to wr.path("/path") returns a new WebResource instance.


> The javadoc for the type method is "Set the media type" but it is not
> the case as internally, it instantiates a new object.
>

> Ok the return type is not a WebResource but the interfaces are the
> same. So it's too easy to fall into the trap...
>

Yes, RequestBuilder s a generic interface that is reused be the class
that initiates building and the builder returned by the initiator.


> Is it possible to be clearer and eventually change the documentation ?
>


Sure, can you log a bug?

I think we can override the JavaDoc for the RequestBuilder methods
implemented by WebResource.

Paul.