Search in sources :

Example 21 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class SettingsDownloader method fetchUsingSettingsWS.

private void fetchUsingSettingsWS(@Nullable String moduleKey, BiConsumer<String, String> consumer) {
    String url = API_SETTINGS_PATH;
    if (moduleKey != null) {
        url += "?component=" + StringUtils.urlEncode(moduleKey);
    }
    WsResponse response = wsClient.get(url);
    try (InputStream is = response.contentStream()) {
        ValuesWsResponse values = ValuesWsResponse.parseFrom(is);
        for (Setting s : values.getSettingsList()) {
            // Storage optimisation: don't store settings having same value than global settings
            if (!s.getInherited()) {
                processSetting(consumer, s);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Unable to parse properties from: " + response.content(), e);
    }
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) InputStream(java.io.InputStream) Setting(org.sonarqube.ws.Settings.Setting) WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) IOException(java.io.IOException)

Example 22 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class SettingsDownloader method fetchUsingPropertiesWS.

private void fetchUsingPropertiesWS(@Nullable String moduleKey, BiPredicate<String, String> filter, BiConsumer<String, String> consumer) {
    String url = API_PROPERTIES_PATH;
    if (moduleKey != null) {
        url += "&resource=" + StringUtils.urlEncode(moduleKey);
    }
    try (WsResponse response = wsClient.get(url)) {
        try (JsonReader reader = new JsonReader(response.contentReader())) {
            reader.beginArray();
            while (reader.hasNext()) {
                reader.beginObject();
                parseProperty(filter, consumer, reader);
                reader.endObject();
            }
            reader.endArray();
        } catch (IOException e) {
            throw new IllegalStateException("Unable to parse properties from: " + response.content(), e);
        }
    }
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) JsonReader(com.google.gson.stream.JsonReader) IOException(java.io.IOException)

Example 23 with WsResponse

use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.

the class ServerVersionAndStatusChecker method tryFromDeprecatedApi.

private ServerInfos tryFromDeprecatedApi(WsResponse originalReponse) {
    // Maybe a server version prior to 5.2. Fallback on deprecated api/server/version
    try (WsResponse responseFallback = wsClient.rawGet("api/server/version")) {
        if (!responseFallback.isSuccessful()) {
            // We prefer to report original error
            throw SonarLintWsClient.handleError(originalReponse);
        }
        String responseStr = responseFallback.content();
        ServerInfos.Builder builder = ServerInfos.newBuilder();
        builder.setStatus("UP");
        builder.setVersion(trimToEmpty(responseStr));
        return builder.build();
    }
}
Also used : WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Aggregations

WsResponse (org.sonarsource.sonarlint.core.util.ws.WsResponse)23 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 Gson (com.google.gson.Gson)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CheckForNull (javax.annotation.CheckForNull)2 Test (org.junit.Test)2 ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)2 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)2 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)2 JsonReader (com.google.gson.stream.JsonReader)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 LinkedList (java.util.LinkedList)1 Scanner (java.util.Scanner)1 Paging (org.sonarqube.ws.Common.Paging)1 Setting (org.sonarqube.ws.Settings.Setting)1