use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ReportPublisher method upload.
/**
* Uploads the report file to server and returns the generated task id
*/
@VisibleForTesting
String upload(File report) {
LOG.debug("Upload report");
long startTime = System.currentTimeMillis();
ProjectDefinition projectDefinition = projectReactor.getRoot();
PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
PostRequest post = new PostRequest("api/ce/submit").setMediaType(MediaTypes.PROTOBUF).setParam("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)).setParam("projectKey", projectDefinition.getKey()).setParam("projectName", projectDefinition.getOriginalName()).setParam("projectBranch", projectDefinition.getBranch()).setPart("report", filePart);
WsResponse response;
try {
response = wsClient.call(post).failIfNotSuccessful();
} catch (HttpException e) {
throw MessageException.of(String.format("Failed to upload report - %d: %s", e.code(), ScannerWsClient.tryParseAsJsonError(e.content())));
}
try (InputStream protobuf = response.contentStream()) {
return WsCe.SubmitResponse.parser().parseFrom(protobuf).getTaskId();
} catch (Exception e) {
throw Throwables.propagate(e);
} finally {
long stopTime = System.currentTimeMillis();
LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms");
}
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method fail_if_requires_permission.
@Test
public void fail_if_requires_permission() throws Exception {
expectedException.expect(MessageException.class);
expectedException.expectMessage("missing scan permission, missing another permission");
WsRequest request = newRequest();
WsResponse response = newResponse().setCode(403).setContent("{\"errors\":[{\"msg\":\"missing scan permission\"}, {\"msg\":\"missing another permission\"}]}");
when(wsClient.wsConnector().call(request)).thenReturn(response);
new ScannerWsClient(wsClient, true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method log_and_profile_request_if_debug_level.
@Test
public void log_and_profile_request_if_debug_level() throws Exception {
WsRequest request = newRequest();
WsResponse response = newResponse().setRequestUrl("https://local/api/issues/search");
when(wsClient.wsConnector().call(request)).thenReturn(response);
logTester.setLevel(LoggerLevel.DEBUG);
ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap())));
WsResponse result = underTest.call(request);
// do not fail the execution -> interceptor returns the response
assertThat(result).isSameAs(response);
// check logs
List<String> debugLogs = logTester.logs(LoggerLevel.DEBUG);
assertThat(debugLogs).hasSize(1);
assertThat(debugLogs.get(0)).contains("GET 200 https://local/api/issues/search | time=");
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method fail_if_credentials_are_not_valid.
@Test
public void fail_if_credentials_are_not_valid() throws Exception {
expectedException.expect(MessageException.class);
expectedException.expectMessage("Not authorized. Please check the properties sonar.login and sonar.password.");
WsRequest request = newRequest();
WsResponse response = newResponse().setCode(401);
when(wsClient.wsConnector().call(request)).thenReturn(response);
new ScannerWsClient(wsClient, /* credentials are configured */
true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockStream.
public static void mockStream(ScannerWsClient mock, String path, InputStream is) {
WsResponse response = mock(WsResponse.class);
when(response.contentStream()).thenReturn(is);
when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
}
Aggregations