aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar/wsclient
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-06-06 17:15:18 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-06-06 17:15:18 +0200
commit48df13d33938b36a1af7feed65e9bb464af597e2 (patch)
tree053bd8ecc35e3d2bb013d83f688b8a5845f201ad /sonar-ws-client/src/main/java/org/sonar/wsclient
parentf1c7b9f5601d77f9ffa35c4f61129c898292299b (diff)
downloadsonarqube-48df13d33938b36a1af7feed65e9bb464af597e2.tar.gz
sonarqube-48df13d33938b36a1af7feed65e9bb464af597e2.zip
SONAR-3755 Fix bug in Issue WS Client when encoding dates
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar/wsclient')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java
index 4d10be6f043..d022f5960b7 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java
@@ -22,6 +22,10 @@ package org.sonar.wsclient.internal;
import com.github.kevinsawicki.http.HttpRequest;
import javax.annotation.Nullable;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.LinkedHashMap;
import java.util.Map;
/**
@@ -116,15 +120,36 @@ public class HttpRequestFactory {
}
public HttpRequest get(String wsUrl, Map<String, Object> queryParams) {
- HttpRequest request = HttpRequest.get(baseUrl + wsUrl, queryParams, true);
+ HttpRequest request = HttpRequest.get(baseUrl + wsUrl, encode(queryParams), false);
return prepare(request);
}
public HttpRequest post(String wsUrl, Map<String, Object> queryParams) {
- HttpRequest request = HttpRequest.post(baseUrl + wsUrl, queryParams, true);
+ HttpRequest request = HttpRequest.post(baseUrl + wsUrl, encode(queryParams), false);
return prepare(request);
}
+ private static Map<String, Object> encode(Map<String, Object> queryParams){
+ Map<String, Object> newQueryParams = new LinkedHashMap<String, Object>();
+ for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
+ newQueryParams.put(entry.getKey(), encode(entry.getValue()));
+ }
+ return newQueryParams;
+ }
+
+ private static String encode(Object value){
+ try {
+ if (value != null) {
+ return URLEncoder.encode(value.toString(), "UTF-8");
+ }
+ else {
+ return "";
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("Fail to encore parameter", e);
+ }
+ }
+
private HttpRequest prepare(HttpRequest request) {
if (proxyHost != null) {
request.useProxy(proxyHost, proxyPort);