On Thu, 2013-10-31 at 14:14 +0000, Jacob R Quant wrote:
> > On Wed, 2013-10-30 at 18:00 +0000, Jacob R Quant wrote:
> > > It seems like the preferred way to manipulate the query string associated
> > > with a URI
> > > when using org.apache.http.client.utils.URIBuilder is using the
> > > [set|clear|add]Parameter[s] methods rather than the setQuery and
> > > removeQuery methods. However, while the setQuery method is deprecated the
> > > removeQuery method is not. Is this an oversight or is there a specific
> > > reason for this? I would like to understand their intended uses better.
> > >
> > > (snip)
> >
> > The reason for deprecation of the #setQuery method was its inconsistency of
> > its contract with all other methods of the class. #setQuery expected input
> > to be URL encoded whereas all other methods expect unescaped input. The
> > choice was between changing the contract of the method and by doing so
> > breaking pretty much every single application reliant on URIBuilder or
> > method deprecation in favor of another method with slightly less intuitive
> > name. So, one should be using [set|clear| add]Parameter[s] methods to work
> > with query parameters and the #setCustomQueury method to set custom queries.
> >
> > Hope this helps
> >
> > Oleg
>
> Oleg,
>
> Thank you for that explanation. The point about the URL encoding makes
> perfect sense. So if I understand correctly #setCustomQuery is the
> replacement for #setQuery.
Yes, it is.
> As for the clearing operation, one could use #clearQuery in both cases
> (parameters or custom query), but there is also a #clearParameters method for
> naming consistency. Please let me know if that is incorrect.
>
For the lack of better ideas, yes it is basically just for symmetry. The
only subtle difference is that #clearParameters will have no effect on
custom query if it is set.
Consider this example
---
URIBuilder builder = new URIBuilder();
builder
.addParameter("p1", "v2")
.addParameter("p2", "v2").setCustomQuery("I changed my mind");
System.out.println(builder.build());
builder
.clearParameters();
System.out.println(builder.build());
---
---
?I%20changed%20my%20mind
?I%20changed%20my%20mind
---
Oleg
> Jacob
> ******************************************************************************
> "This message and any attachments are solely for the intended recipient and
> may contain confidential or privileged information. If you are not the
> intended recipient, any disclosure, copying, use, or distribution of the
> information included in this message and any attachments is prohibited. If
> you have received this communication in error, please notify us by reply
> e-mail and immediately and permanently delete this message and any
> attachments. Thank you."
> ******************************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]