private String buildUrl(String urlBeginning, Map queryParams) {
StringBuffer builder = new StringBuffer(urlBeginning);
if (queryParams.size() > 0) {
builder.append("?"); //add ? only if query params exist
boolean addingfirstPair = true; //this var is used only to make sure & after last pair is not added
Iterator iterator = queryParams.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
if (!addingfirstPair) {
builder.append("&");
}
builder.append(entry.getKey()).append("=").append(entry.getValue());