diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-01-31 12:05:58 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-01-31 12:06:05 +0100 |
commit | 47de0ecd410920fc000151f5c528b97b28505ec9 (patch) | |
tree | fcb7f4b6dd93cc36fd6fd044281dbc5ffa4ec23a /sonar-ws-client/src/main/java/org/sonar | |
parent | af595f0fda1855b09033a0ed98c955db0c5432c6 (diff) | |
download | sonarqube-47de0ecd410920fc000151f5c528b97b28505ec9.tar.gz sonarqube-47de0ecd410920fc000151f5c528b97b28505ec9.zip |
WS client should consider codes other than 200 for success
Diffstat (limited to 'sonar-ws-client/src/main/java/org/sonar')
-rw-r--r-- | sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java | 14 |
1 files changed, 13 insertions, 1 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 184559fcde4..e20513ee7f2 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,13 +23,21 @@ import com.github.kevinsawicki.http.HttpRequest; import org.sonar.wsclient.base.HttpException; import javax.annotation.Nullable; + +import java.util.Arrays; import java.util.Map; +import static java.net.HttpURLConnection.HTTP_CREATED; +import static java.net.HttpURLConnection.HTTP_NO_CONTENT; +import static java.net.HttpURLConnection.HTTP_OK; + /** * Not an API. Please do not use this class, except maybe for unit tests. */ public class HttpRequestFactory { + private final static int[] RESPONSE_SUCCESS = {HTTP_OK, HTTP_CREATED, HTTP_NO_CONTENT}; + private final String baseUrl; private String login, password, proxyHost, proxyLogin, proxyPassword; private int proxyPort; @@ -128,7 +136,7 @@ public class HttpRequestFactory { private String execute(HttpRequest request) { try { - if (request.ok()) { + if (isSuccess(request)) { return request.body(HttpRequest.CHARSET_UTF8); } // TODO handle error messages @@ -139,6 +147,10 @@ public class HttpRequestFactory { } } + private boolean isSuccess(HttpRequest request) { + return Arrays.binarySearch(RESPONSE_SUCCESS, request.code()) >= 0; + } + private HttpRequest prepare(HttpRequest request) { if (proxyHost != null) { request.useProxy(proxyHost, proxyPort); |