org.sonarqube.ws.client.WsConnector类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中org.sonarqube.ws.client.WsConnector类的一些代码示例,展示了WsConnector类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WsConnector类的具体详情如下:
包路径:org.sonarqube.ws.client.WsConnector
类名称:WsConnector

WsConnector介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

  1. protected WsResponse call(WsRequest request) {
  2. return wsConnector.call(request).failIfNotSuccessful();
  3. }

代码示例来源:origin: SonarSource/sonarqube

  1. public String baseUrl() {
  2. return target.wsConnector().baseUrl();
  3. }

代码示例来源:origin: gabrie-allaigre/sonar-gitlab-plugin

  1. private Rules.ShowResponse showRule(String ruleKey) {
  2. GetRequest getRequest = new GetRequest("api/rules/show").setParam("key", ruleKey).setMediaType(MediaTypes.PROTOBUF);
  3. WsResponse wsResponse = wsClient.wsConnector().call(getRequest);
  4. if (wsResponse.code() != 200) {
  5. throw new HttpException(wsClient.wsConnector().baseUrl() + toString(getRequest), wsResponse.code(), wsResponse.content());
  6. }
  7. try {
  8. return Rules.ShowResponse.parseFrom(wsResponse.contentStream());
  9. } catch (IOException e) {
  10. throw new IllegalStateException(e.getMessage(), e);
  11. }
  12. }

代码示例来源:origin: SonarSource/sonarqube

  1. public void test() {
  2. GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
  3. when(wsConnector.call(get)).thenReturn(newProtobufFakeResponse());
  4. Testing.Fake message = call(get, Testing.Fake.parser());
  5. assertThat(message.getLabel()).isEqualTo("ok");
  6. assertThat(get.getPath()).isEqualTo("api/issues/issue");
  7. // media type automatically set to protobuf
  8. assertThat(get.getMediaType()).isEqualTo(MediaTypes.PROTOBUF);
  9. }

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

  1. public String baseUrl() {
  2. return target.wsConnector().baseUrl();
  3. }

代码示例来源:origin: SonarSource/sonarqube

  1. /**
  2. * If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the
  3. * body content's stream/reader.
  4. *
  5. * @throws IllegalStateException if the request could not be executed due to a connectivity problem or timeout. Because networks can
  6. * fail during an exchange, it is possible that the remote server accepted the request before the failure
  7. * @throws MessageException if there was a problem with authentication or if a error message was parsed from the response.
  8. * @throws HttpException if the response code is not in range [200..300). Consider using {@link #createErrorMessage(HttpException)} to create more relevant messages for the users.
  9. */
  10. public WsResponse call(WsRequest request) {
  11. Preconditions.checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode");
  12. Profiler profiler = Profiler.createIfDebug(LOG).start();
  13. WsResponse response = target.wsConnector().call(request);
  14. profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl()));
  15. failIfUnauthorized(response);
  16. return response;
  17. }

代码示例来源:origin: org.sonarsource.sonarqube/sonar-scanner-engine

  1. public String baseUrl() {
  2. return target.wsConnector().baseUrl();
  3. }

代码示例来源:origin: SonarSource/sonarqube

  1. public void test() throws IOException {
  2. GetRequest get = new GetRequest(path("issue")).setMediaType(MediaTypes.JSON);
  3. when(wsConnector.call(get)).thenReturn(new MockWsResponse().setContent("ok"));
  4. WsResponse response = call(get);
  5. assertThat(response.content()).isEqualTo("ok");
  6. }

代码示例来源:origin: SonarSource/sonarqube

  1. public void test() {
  2. GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
  3. when(wsConnector.call(get)).thenReturn(MockWsResponse.createJson("{}").setRequestUrl("http://local/api/issues/issue?key=ABC"));
  4. try {
  5. call(get, Testing.Fake.parser());
  6. fail();
  7. } catch (IllegalStateException e) {
  8. assertThat(e).hasMessage("Fail to parse protobuf response of http://local/api/issues/issue?key=ABC");
  9. }
  10. }
  11. }.test();

代码示例来源:origin: SonarSource/sonarqube

  1. @Test
  2. public void log_and_profile_request_if_debug_level() {
  3. WsRequest request = newRequest();
  4. WsResponse response = newResponse().setRequestUrl("https://local/api/issues/search");
  5. when(wsClient.wsConnector().call(request)).thenReturn(response);
  6. logTester.setLevel(LoggerLevel.DEBUG);
  7. ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())));
  8. WsResponse result = underTest.call(request);
  9. // do not fail the execution -> interceptor returns the response
  10. assertThat(result).isSameAs(response);
  11. // check logs
  12. List<String> debugLogs = logTester.logs(LoggerLevel.DEBUG);
  13. assertThat(debugLogs).hasSize(1);
  14. assertThat(debugLogs.get(0)).contains("GET 200 https://local/api/issues/search | time=");
  15. }

代码示例来源:origin: SonarSource/sonarqube

  1. public void test() {
  2. GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
  3. when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error"));
  4. try {
  5. call(get, Testing.Fake.parser());
  6. fail();
  7. } catch (HttpException e) {
  8. assertThat(e.code()).isEqualTo(403);
  9. }
  10. }

代码示例来源:origin: SonarSource/sonarqube

  1. @Test
  2. public void fail_if_requires_credentials() {
  3. expectedException.expect(MessageException.class);
  4. expectedException
  5. .expectMessage("Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.");
  6. WsRequest request = newRequest();
  7. WsResponse response = newResponse().setCode(401);
  8. when(wsClient.wsConnector().call(request)).thenReturn(response);
  9. new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
  10. }

代码示例来源:origin: SonarSource/sonarqube

  1. @Test
  2. public void fail_if_credentials_are_not_valid() {
  3. expectedException.expect(MessageException.class);
  4. expectedException.expectMessage("Not authorized. Please check the properties sonar.login and sonar.password.");
  5. WsRequest request = newRequest();
  6. WsResponse response = newResponse().setCode(401);
  7. when(wsClient.wsConnector().call(request)).thenReturn(response);
  8. new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
  9. }

代码示例来源:origin: SonarSource/sonarqube

  1. @Test
  2. public void fail_if_requires_permission() {
  3. expectedException.expect(MessageException.class);
  4. expectedException.expectMessage("You're not authorized to run analysis. Please contact the project administrator.");
  5. WsRequest request = newRequest();
  6. WsResponse response = newResponse()
  7. .setCode(403);
  8. when(wsClient.wsConnector().call(request)).thenReturn(response);
  9. new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
  10. }

代码示例来源:origin: SonarSource/sonarqube

  1. @Test
  2. public void fail_if_bad_request() {
  3. expectedException.expect(MessageException.class);
  4. expectedException.expectMessage("Boo! bad request! bad!");
  5. WsRequest request = newRequest();
  6. WsResponse response = newResponse()
  7. .setCode(400)
  8. .setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
  9. when(wsClient.wsConnector().call(request)).thenReturn(response);
  10. new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
  11. }

代码示例来源:origin: org.sonarsource.sonarqube/sonar-ws

  1. protected WsResponse call(WsRequest request) {
  2. return wsConnector.call(request).failIfNotSuccessful();
  3. }

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

  1. /**
  2. * @throws IllegalStateException if the request could not be executed due to
  3. * a connectivity problem or timeout. Because networks can
  4. * fail during an exchange, it is possible that the remote server
  5. * accepted the request before the failure
  6. * @throws HttpException if the response code is not in range [200..300)
  7. */
  8. public WsResponse call(WsRequest request) {
  9. Profiler profiler = Profiler.createIfDebug(LOG).start();
  10. WsResponse response = target.wsConnector().call(request);
  11. profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl()));
  12. failIfUnauthorized(response);
  13. return response;
  14. }

代码示例来源:origin: org.sonarsource.sonarqube/sonar-scanner-engine

  1. /**
  2. * If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the
  3. * body content's stream/reader.
  4. *
  5. * @throws IllegalStateException if the request could not be executed due to a connectivity problem or timeout. Because networks can
  6. * fail during an exchange, it is possible that the remote server accepted the request before the failure
  7. * @throws MessageException if there was a problem with authentication or if a error message was parsed from the response.
  8. * @throws HttpException if the response code is not in range [200..300). Consider using {@link #createErrorMessage(HttpException)} to create more relevant messages for the users.
  9. */
  10. public WsResponse call(WsRequest request) {
  11. Preconditions.checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode");
  12. Profiler profiler = Profiler.createIfDebug(LOG).start();
  13. WsResponse response = target.wsConnector().call(request);
  14. profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl()));
  15. failIfUnauthorized(response);
  16. return response;
  17. }

代码示例来源:origin: SonarQubeCommunity/sonar-build-breaker

  1. WsResponse wsResponse = wsClient.wsConnector().call(ceTaskRequest);

相关文章