QueryStringEncoder encoder = new QueryStringEncoder(uri.toString());
for (Map.Entry<String, Object> e : params.entrySet()) {
encoder.addParam(e.getKey(), String.valueOf(e.getValue()));
}
try {
return encoder.toUri();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Cannot construct a query string from the given params. " +
"An invalid parameter was used.");
}
}