users@jersey.java.net

Some weird issue with a combination of Client, WebResource and UriBuilder APIs

From: Srinivas Naresh Bhimisetty <Srinivas.Bhimisetty_at_Sun.COM>
Date: Tue, 23 Sep 2008 19:41:05 +0530

Hi,

   I see some weird behavior when I try executing the following code
fragment:
===========================================================
        UriBuilder requestUriBuilder =
wr.path("resources").path("resource3")
                .path(arg1).path(arg2).getBuilder().queryParam("rep", 0);
        URI requestUri = requestUriBuilder.build();
        wr = c.resource(requestUri);
        System.out.println("0:" + requestUri.toURL().toString());

        // replace the query param "rep=0" with "rep=1"
        requestUriBuilder = requestUriBuilder.replaceQueryParam("rep", 1);
        requestUri = requestUriBuilder.build();
        wr = c.resource(requestUri);
        System.out.println("1:" + requestUri.toURL().toString());

        //replace "rep=1" with "rep=2"
        requestUriBuilder = requestUriBuilder.replaceQueryParam("rep", 2);
        requestUri = requestUriBuilder.build();
        wr = c.resource(requestUri);
        System.out.println("2:" + requestUri.toURL().toString());
==========================================================

   The output when I execute the above is something like:

============================================================
0:http://localhost:9988/SimpleServlet/resources/resource3/firstArg/secondArg?rep=0
1:http://localhost:9988/SimpleServlet/resources/resource3/firstArg/secondArg?rep=1
2:http://localhost:9988/SimpleServlet/resources/resource3/firstArg/secondArg?rep=1&rep=2
=============================================================

  It can be seen that in the third attempt there are two values for
"rep". Is it something intended?
  
Thanks,
Naresh