Hi Tyson,
WebResource is designed so that you cannot modify the URI it has been
created with (it is also reentrant).
You modify state on the WebResource.Builder that is returned invoking
certain methods on WebResource.
WebResource wr = c.resource("
http://localhost:8081/Test/resources/");
WebResource.Builder wrb = wr.path("foo/");
String jsonData = wrb.accept("application/json").get(String.class);
So you are correct in your assumptions you describe below.
Like the previous email i sent we can improve the JavaDoc here :-)
Paul.
Tyson Norris wrote:
> Hi All –
>
> In a first attempt at creating a java based client using Jersey 0.8 with:
>
> com.sun.jersey.api.client.Client
>
> com.sun.jersey.api.client.WebResource
>
>
>
>
>
> I noticed that running the following works:
>
> WebResource wr = c.resource("http://localhost:8081/Test/resources/");
>
> String jsonData =
> wr.path("foo/").accept("application/json").get(String.class);
>
>
>
>
>
> But this does NOT work:
>
> WebResource wr = c.resource("http://localhost:8081/Test/resources/");
>
> wr.path("foo/");
>
> String jsonData = wr.accept("application/json").get(String.class);
>
>
>
> I did also try this which DOES work:
>
> WebResource wr = c.resource("http://localhost:8081/Test/resources/foo");
>
> String jsonData =wr.get(String.class);
>
>
>
> It seems like WebResource.get() will only work if there is no need to
> use the WebResource.accept() or WebResource.path() methods. If accept()
> and path() are required, then you MUST execute WebResource.Builder.get()
> (instead of WebResource.get()).
>
>
>
> Is this all correct? I got very confused when I changed syntax from the
> chained-method syntax to separate statements, and then realized that the
> methods return WebResource.Builder when I assumed it returned WebResource.
>
>
>
> Thanks!
>
> Tyson
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109