private Map<String, QualityProfile> call(String url) throws IOException { GetRequest getRequest = new GetRequest(url); try (InputStream is = wsClient.call(getRequest).contentStream()) { SearchWsResponse profiles = SearchWsResponse.parseFrom(is); List<QualityProfile> profilesList = profiles.getProfilesList(); return profilesList.stream().collect(toMap(QualityProfile::getLanguage, identity(), throwingMerger(), LinkedHashMap::new)); } }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules/list">Further information about this action online (including a response example)</a> * @since 5.2 */ public ListResponse list() { return call( new GetRequest(path("list")), ListResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/system/status">Further information about this action online (including a response example)</a> * @since 5.2 */ public StatusResponse status() { return call( new GetRequest(path("status")), StatusResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/users/current">Further information about this action online (including a response example)</a> * @since 5.2 */ public CurrentWsResponse current() { return call( new GetRequest(path("current")), CurrentWsResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/users/identity_providers">Further information about this action online (including a response example)</a> * @since 5.5 */ public IdentityProvidersWsResponse identityProviders() { return call( new GetRequest(path("identity_providers")), IdentityProvidersWsResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/settings/check_secret_key">Further information about this action online (including a response example)</a> * @since 6.1 */ public CheckSecretKeyWsResponse checkSecretKey() { return call( new GetRequest(path("check_secret_key")), CheckSecretKeyWsResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/settings/generate_secret_key">Further information about this action online (including a response example)</a> * @since 6.1 */ public GenerateSecretKeyWsResponse generateSecretKey() { return call( new GetRequest(path("generate_secret_key")), GenerateSecretKeyWsResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/system/health">Further information about this action online (including a response example)</a> * @since 6.6 */ public HealthResponse health() { return call( new GetRequest(path("health")), HealthResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/ce/info">Further information about this action online (including a response example)</a> * @since 7.2 */ public InfoWsResponse info() { return call( new GetRequest(path("info")), InfoWsResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/ce/task_types">Further information about this action online (including a response example)</a> * @since 5.5 */ public TaskTypesWsResponse taskTypes() { return call( new GetRequest(path("task_types")), TaskTypesWsResponse.parser()); }
/** * * This is part of the internal API. * This is a GET request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/roots/search">Further information about this action online (including a response example)</a> * @since 6.2 */ public SearchResponse search() { return call( new GetRequest(path("search")), SearchResponse.parser()); }
@Override public List<Rule> load() { GetRequest getRequest = new GetRequest(RULES_SEARCH_URL); ListResponse list = loadFromStream(wsClient.call(getRequest).contentStream()); return list.getRulesList(); }
@Override public void load(String componentKey, Consumer<ServerIssue> consumer) { GetRequest getRequest = new GetRequest("/batch/issues.protobuf?key=" + ScannerUtils.encodeForUrl(componentKey)); InputStream is = wsClient.call(getRequest).contentStream(); parseIssues(is, consumer); }
@Test public void support_base_url_with_context() { // just to be sure assertThat(serverUrl).endsWith("/"); underTest = HttpConnector.newBuilder().url(serverUrl + "sonar").build(); GetRequest request = new GetRequest("api/issues/search"); answerHelloWorld(); assertThat(underTest.call(request).requestUrl()).isEqualTo(serverUrl + "sonar/api/issues/search"); request = new GetRequest("/api/issues/search"); answerHelloWorld(); assertThat(underTest.call(request).requestUrl()).isEqualTo(serverUrl + "sonar/api/issues/search"); }
public void test() { GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC"); when(wsConnector.call(get)).thenReturn(MockWsResponse.createJson("{}").setRequestUrl("http://local/api/issues/issue?key=ABC")); try { call(get, Testing.Fake.parser()); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage("Fail to parse protobuf response of http://local/api/issues/issue?key=ABC"); } } }.test();
@Test public void support_base_url_ending_with_slash() throws Exception { assertThat(serverUrl).endsWith("/"); underTest = HttpConnector.newBuilder().url(StringUtils.removeEnd(serverUrl, "/")).build(); GetRequest request = new GetRequest("api/issues/search"); answerHelloWorld(); WsResponse response = underTest.call(request); assertThat(response.hasContent()).isTrue(); }
public void test() { GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC"); when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error")); try { call(get, Testing.Fake.parser()); fail(); } catch (HttpException e) { assertThat(e.code()).isEqualTo(403); } }
@Test public void send_user_agent() throws Exception { answerHelloWorld(); underTest = HttpConnector.newBuilder() .url(serverUrl) .userAgent("Maven Plugin/2.3") .build(); underTest.call(new GetRequest("api/issues/search")); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest.getHeader("User-Agent")).isEqualTo("Maven Plugin/2.3"); }
@Test public void use_basic_authentication() throws Exception { answerHelloWorld(); underTest = HttpConnector.newBuilder() .url(serverUrl) .credentials("theLogin", "thePassword") .build(); GetRequest request = new GetRequest("api/issues/search"); underTest.call(request); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest.getHeader("Authorization")).isEqualTo(basic("theLogin", "thePassword")); }
@Test public void use_basic_authentication_with_null_password() throws Exception { answerHelloWorld(); underTest = HttpConnector.newBuilder() .url(serverUrl) .credentials("theLogin", null) .build(); GetRequest request = new GetRequest("api/issues/search"); underTest.call(request); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest.getHeader("Authorization")).isEqualTo(basic("theLogin", "")); }