aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws/src/main
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-05-10 21:47:15 +0200
committerSonarTech <sonartech@sonarsource.com>2018-05-11 20:20:47 +0200
commit01e1c69fe35fac0678130f5784ee0b70422c8536 (patch)
tree5c39a4b19872e6cbe75a229f43bc52ddb14912b9 /sonar-ws/src/main
parent54a47fb03ec189410fa6d53a5355b2116624fe33 (diff)
downloadsonarqube-01e1c69fe35fac0678130f5784ee0b70422c8536.tar.gz
sonarqube-01e1c69fe35fac0678130f5784ee0b70422c8536.zip
SONAR-10591 scanner uses WS api/plugins/download
Diffstat (limited to 'sonar-ws/src/main')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java2
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java8
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java17
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java11
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java3
5 files changed, 33 insertions, 8 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
index df154463a1d..bbb268f1be0 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseResponse.java
@@ -42,7 +42,7 @@ abstract class BaseResponse implements WsResponse {
public boolean hasContent() {
return code() != HTTP_NO_CONTENT;
}
-
+
@Override
public void close() {
// override if needed
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java
index 2a9209af4e1..823e364ae03 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java
@@ -140,5 +140,13 @@ class LocalWsConnector implements WsConnector {
public String content() {
return new String(bytes, UTF_8);
}
+
+ /**
+ * Not implemented yet
+ */
+ @Override
+ public Optional<String> header(String name) {
+ return Optional.empty();
+ }
}
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java
index 7003b8f238c..789d61850d3 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java
@@ -27,6 +27,9 @@ import java.io.Reader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
import org.apache.commons.io.IOUtils;
import org.sonarqube.ws.MediaTypes;
@@ -34,10 +37,12 @@ import static java.util.Objects.requireNonNull;
public class MockWsResponse extends BaseResponse {
+ private static final String CONTENT_TYPE_HEADER = "Content-Type";
+
private int code = HttpURLConnection.HTTP_OK;
private String requestUrl;
private byte[] content;
- private String contentType;
+ private final Map<String,String> headers = new HashMap<>();
@Override
public int code() {
@@ -51,12 +56,16 @@ public class MockWsResponse extends BaseResponse {
@Override
public String contentType() {
- requireNonNull(contentType);
- return contentType;
+ return requireNonNull(headers.get(CONTENT_TYPE_HEADER));
+ }
+
+ @Override
+ public Optional<String> header(String name) {
+ return Optional.ofNullable(headers.get(name));
}
public MockWsResponse setContentType(String contentType) {
- this.contentType = contentType;
+ headers.put(CONTENT_TYPE_HEADER, contentType);
return this;
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
index 239d4ebb609..9c0e1ec9968 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
@@ -19,12 +19,12 @@
*/
package org.sonarqube.ws.client;
-import okhttp3.Response;
-import okhttp3.ResponseBody;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.util.Optional;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
class OkHttpResponse extends BaseResponse {
@@ -49,6 +49,11 @@ class OkHttpResponse extends BaseResponse {
return okResponse.header("Content-Type");
}
+ @Override
+ public Optional<String> header(String name) {
+ return Optional.ofNullable(okResponse.header(name));
+ }
+
/**
* Get stream of bytes
*/
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
index aeb297b399a..8847e040782 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java
@@ -22,6 +22,7 @@ package org.sonarqube.ws.client;
import java.io.Closeable;
import java.io.InputStream;
import java.io.Reader;
+import java.util.Optional;
/**
* @since 5.3
@@ -51,6 +52,8 @@ public interface WsResponse extends Closeable {
String contentType();
+ Optional<String> header(String name);
+
boolean hasContent();
InputStream contentStream();