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);
}
}
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);
}
}
}
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();
}
}
Aggregations