You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Jacob R Quant <ja...@ampf.com> on 2013/10/30 19:00:47 UTC

Since URIBuilder.setQuery is deprecated shouldn't clearQuery also be deprecated?

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.

BTW, I posted a question about this at StackOverflow.com as well, but I am not sure if members of this list monitor those or not.
http://stackoverflow.com/questions/19668899/what-is-the-difference-between-removequery-and-clearparameters-in-org-ap

Thanks for your time & for your work on HttpComponents/HttpClient!

-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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: Since URIBuilder.setQuery is deprecated shouldn't clearQuery also be deprecated?

Posted by Oleg Kalnichevski <ol...@apache.org>.
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: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


RE: Since URIBuilder.setQuery is deprecated shouldn't clearQuery also be deprecated?

Posted by Jacob R Quant <ja...@ampf.com>.
> 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. 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.

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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: Since URIBuilder.setQuery is deprecated shouldn't clearQuery also be deprecated?

Posted by Oleg Kalnichevski <ol...@apache.org>.
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  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.
> 
> BTW, I posted a question about this at StackOverflow.com as well, but I am not sure if members of this list monitor those or not.
> http://stackoverflow.com/questions/19668899/what-is-the-difference-between-removequery-and-clearparameters-in-org-ap
> 

Jacob

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  



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org