From 19170ca15132f97a5c8f9c32943cd2a7b6af074b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 7 Jun 2013 09:48:30 +0200 Subject: [PATCH] SONAR-3755 Update com.github.kevinsawicki:http-request version to 5.2 that fix issue when encoding + character --- pom.xml | 2 +- .../wsclient/internal/HttpRequestFactory.java | 28 ++----------------- .../internal/HttpRequestFactoryTest.java | 4 +-- .../issue/DefaultActionPlanClientTest.java | 24 ++++++++-------- .../issue/DefaultIssueClientTest.java | 4 +-- .../wsclient/user/DefaultUserClientTest.java | 2 +- 6 files changed, 20 insertions(+), 44 deletions(-) diff --git a/pom.xml b/pom.xml index 2165236824b..7c70852c560 100644 --- a/pom.xml +++ b/pom.xml @@ -1058,7 +1058,7 @@ com.github.kevinsawicki http-request - 5.1 + 5.2 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 d022f5960b7..a601df34efc 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 @@ -23,9 +23,6 @@ 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; /** @@ -120,36 +117,15 @@ public class HttpRequestFactory { } public HttpRequest get(String wsUrl, Map queryParams) { - HttpRequest request = HttpRequest.get(baseUrl + wsUrl, encode(queryParams), false); + HttpRequest request = HttpRequest.get(baseUrl + wsUrl, queryParams, true); return prepare(request); } public HttpRequest post(String wsUrl, Map queryParams) { - HttpRequest request = HttpRequest.post(baseUrl + wsUrl, encode(queryParams), false); + HttpRequest request = HttpRequest.post(baseUrl + wsUrl, queryParams, true); 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); diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/internal/HttpRequestFactoryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/internal/HttpRequestFactoryTest.java index 0c3151017a4..0006ad7295b 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/internal/HttpRequestFactoryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/internal/HttpRequestFactoryTest.java @@ -99,13 +99,13 @@ public class HttpRequestFactoryTest { IssueClient client = new DefaultIssueClient(requestFactory); client.find(IssueQuery.create().issues("ABC DE")); - assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC+DE"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%20DE"); client.find(IssueQuery.create().issues("ABC+BDE")); assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%2BBDE"); client.find(IssueQuery.create().createdAfter(toDate("2013-01-01"))); - assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?createdAfter=2013-01-01T00%3A00%3A00%2B0100"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?createdAfter=2013-01-01T00:00:00%2B0100"); } protected static Date toDate(String sDate) { diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java index 1bddcc0bc1a..e56572fc2b1 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java @@ -42,20 +42,20 @@ public class DefaultActionPlanClientTest { public void should_find_action_plans() { HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url()); httpServer.doReturnBody("{\"actionPlans\": [{\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\",\n" + - "\"name\": \"Long term\",\n" + - "\"status\": \"CLOSED\",\n" + - "\"project\": \"com.sonarsource.it.samples:simple-sample\",\n" + - "\"userLogin\": \"admin\",\n" + - "\"deadLine\": \"2013-05-30T00:00:00+0200\",\n" + - "\"totalIssues\": 3,\n" + - "\"unresolvedIssues\": 2,\n" + - "\"createdAt\": \"2013-05-13T12:50:29+0200\",\n" + - "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}"); + "\"name\": \"Long term\",\n" + + "\"status\": \"CLOSED\",\n" + + "\"project\": \"com.sonarsource.it.samples:simple-sample\",\n" + + "\"userLogin\": \"admin\",\n" + + "\"deadLine\": \"2013-05-30T00:00:00+0200\",\n" + + "\"totalIssues\": 3,\n" + + "\"unresolvedIssues\": 2,\n" + + "\"createdAt\": \"2013-05-13T12:50:29+0200\",\n" + + "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}"); ActionPlanClient client = new DefaultActionPlanClient(requestFactory); List actionPlans = client.find("com.sonarsource.it.samples:simple-sample"); - assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/search?project=com.sonarsource.it.samples%3Asimple-sample"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/search?project=com.sonarsource.it.samples:simple-sample"); assertThat(actionPlans).hasSize(1); ActionPlan actionPlan = actionPlans.get(0); assertThat(actionPlan.key()).isEqualTo("382f6f2e-ad9d-424a-b973-9b065e04348a"); @@ -79,7 +79,7 @@ public class DefaultActionPlanClientTest { ActionPlan result = client.create( NewActionPlan.create().name("Short term").project("org.sonar.Sample").description("Short term issues").deadLine(stringToDate("2014-01-01"))); - assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/create?project=org.sonar.Sample&description=Short+term+issues&name=Short+term&deadLine=2014-01-01"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/create?project=org.sonar.Sample&description=Short%20term%20issues&name=Short%20term&deadLine=2014-01-01"); assertThat(result).isNotNull(); } @@ -92,7 +92,7 @@ public class DefaultActionPlanClientTest { ActionPlan result = client.update( UpdateActionPlan.create().key("382f6f2e-ad9d-424a-b973-9b065e04348a").name("Short term").description("Short term issues").deadLine(stringToDate("2014-01-01"))); - assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/update?description=Short+term+issues&name=Short+term&deadLine=2014-01-01&key=382f6f2e-ad9d-424a-b973-9b065e04348a"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/update?description=Short%20term%20issues&name=Short%20term&deadLine=2014-01-01&key=382f6f2e-ad9d-424a-b973-9b065e04348a"); assertThat(result).isNotNull(); } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java index 90d4229680e..7ad6f6df3c8 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java @@ -130,7 +130,7 @@ public class DefaultIssueClientTest { IssueClient client = new DefaultIssueClient(requestFactory); Issue result = client.create(NewIssue.create().component("Action.java").rule("squid:AvoidCycle")); - assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/create?component=Action.java&rule=squid%3AAvoidCycle"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/create?component=Action.java&rule=squid:AvoidCycle"); assertThat(result).isNotNull(); } @@ -172,7 +172,7 @@ public class DefaultIssueClientTest { IssueClient client = new DefaultIssueClient(requestFactory); IssueComment comment = client.addComment("ISSUE-1", "this is my comment"); - assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/add_comment?issue=ISSUE-1&text=this+is+my+comment"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/add_comment?issue=ISSUE-1&text=this%20is%20my%20comment"); assertThat(comment).isNotNull(); assertThat(comment.key()).isEqualTo("COMMENT-123"); assertThat(comment.htmlText()).isEqualTo("this is my comment"); diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java index ca327f370ca..716802c6fde 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java @@ -41,7 +41,7 @@ public class DefaultUserClientTest { UserQuery query = UserQuery.create().logins("simon", "loic"); List users = client.find(query); - assertThat(httpServer.requestedPath()).isEqualTo("/api/users/search?logins=simon%2Cloic"); + assertThat(httpServer.requestedPath()).isEqualTo("/api/users/search?logins=simon,loic"); assertThat(users).hasSize(1); User simon = users.get(0); assertThat(simon.login()).isEqualTo("simon"); -- 2.39.5