aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws/src/main/java/org/sonarqube/ws/client
diff options
context:
space:
mode:
authorJacek Poreda <jacek.poreda@sonarsource.com>2023-06-16 10:31:26 +0200
committersonartech <sonartech@sonarsource.com>2023-06-20 13:10:18 +0000
commit740b5b55034ae77af005a67ad209dd11231876c4 (patch)
tree3a70cde35e842837dff4ec2119ea85efe6e4ed84 /sonar-ws/src/main/java/org/sonarqube/ws/client
parent36640146f7c90816579bf68a1b79b8c664242936 (diff)
downloadsonarqube-740b5b55034ae77af005a67ad209dd11231876c4.tar.gz
sonarqube-740b5b55034ae77af005a67ad209dd11231876c4.zip
SONAR-19418 Add debug logging in case error Scanner WS client
Diffstat (limited to 'sonar-ws/src/main/java/org/sonarqube/ws/client')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/LocalWsConnector.java6
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/MockWsResponse.java15
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java7
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/WsResponse.java4
4 files changed, 32 insertions, 0 deletions
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 73abe1907a6..3e806580ba6 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
@@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -159,5 +160,10 @@ class LocalWsConnector implements WsConnector {
public Optional<String> header(String name) {
return Optional.empty();
}
+
+ @Override
+ public Map<String, List<String>> headers() {
+ return new HashMap<>();
+ }
}
}
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 5230ef6afd6..30fabb9731d 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
@@ -25,12 +25,15 @@ import java.io.Reader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.sonarqube.ws.MediaTypes;
import static java.util.Objects.requireNonNull;
+import static java.util.stream.Collectors.*;
public class MockWsResponse extends BaseResponse {
@@ -62,6 +65,13 @@ public class MockWsResponse extends BaseResponse {
return Optional.ofNullable(headers.get(name));
}
+ @Override
+ public Map<String, List<String>> headers() {
+ return headers.entrySet()
+ .stream()
+ .collect(toMap(Map.Entry::getKey, e -> Collections.singletonList(e.getValue())));
+ }
+
public MockWsResponse setContentType(String contentType) {
headers.put(CONTENT_TYPE_HEADER, contentType);
return this;
@@ -87,6 +97,11 @@ public class MockWsResponse extends BaseResponse {
return this;
}
+ public MockWsResponse setHeader(String key, String value) {
+ this.headers.put(key, value);
+ return this;
+ }
+
@Override
public boolean hasContent() {
return content != null;
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 50ad2b6a1b0..d67a7aa47c6 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
@@ -22,6 +22,8 @@ package org.sonarqube.ws.client;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import okhttp3.Response;
import okhttp3.ResponseBody;
@@ -54,6 +56,11 @@ class OkHttpResponse extends BaseResponse {
return Optional.ofNullable(okResponse.header(name));
}
+ @Override
+ public Map<String, List<String>> headers() {
+ return okResponse.headers().toMultimap();
+ }
+
/**
* 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 957fce36e3d..419d519889a 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,8 @@ package org.sonarqube.ws.client;
import java.io.Closeable;
import java.io.InputStream;
import java.io.Reader;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
/**
@@ -54,6 +56,8 @@ public interface WsResponse extends Closeable {
Optional<String> header(String name);
+ Map<String, List<String>> headers();
+
boolean hasContent();
InputStream contentStream();