From 48df13d33938b36a1af7feed65e9bb464af597e2 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 6 Jun 2013 17:15:18 +0200 Subject: SONAR-3755 Fix bug in Issue WS Client when encoding dates --- .../wsclient/internal/HttpRequestFactory.java | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'sonar-ws-client/src/main/java/org/sonar/wsclient') 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 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 queryParams) { - HttpRequest request = HttpRequest.post(baseUrl + wsUrl, queryParams, true); + HttpRequest request = HttpRequest.post(baseUrl + wsUrl, encode(queryParams), false); return prepare(request); } + private static Map encode(Map queryParams){ + Map newQueryParams = new LinkedHashMap(); + for (Map.Entry 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); -- cgit v1.2.3