use of org.sonarqube.ws.client.HttpException in project sonarqube by SonarSource.
the class OrganizationTest method verifyUserNotAuthorized.
private void verifyUserNotAuthorized(String login, String password, Consumer<OrganizationService> consumer) {
try {
OrganizationService organizationService = ItUtils.newUserWsClient(orchestrator, login, password).organizations();
consumer.accept(organizationService);
fail("An HttpException should have been raised");
} catch (HttpException e) {
assertThat(e.code()).isEqualTo(403);
}
}
use of org.sonarqube.ws.client.HttpException in project sonarqube by SonarSource.
the class QualityGateCheck method getQualityGateStatus.
private Status getQualityGateStatus(String analysisId) {
GetRequest getQualityGateReq = new GetRequest("api/qualitygates/project_status").setMediaType(MediaTypes.PROTOBUF).setParam("analysisId", analysisId);
try {
WsResponse getTaskResultResponse = wsClient.call(getQualityGateReq).failIfNotSuccessful();
Qualitygates.ProjectStatusResponse.ProjectStatus status = parseQualityGateResponse(getTaskResultResponse);
return status.getStatus();
} catch (HttpException e) {
throw MessageException.of(String.format("Failed to get Quality Gate status - %s", DefaultScannerWsClient.createErrorMessage(e)));
}
}
use of org.sonarqube.ws.client.HttpException in project sonarqube by SonarSource.
the class QualityGateCheck method waitForCeTaskToFinish.
private Ce.Task waitForCeTaskToFinish(String taskId) {
GetRequest getTaskResultReq = new GetRequest("api/ce/task").setMediaType(MediaTypes.PROTOBUF).setParam("id", taskId);
long currentTime = 0;
while (qualityGateTimeoutInMs > currentTime) {
try {
WsResponse getTaskResultResponse = wsClient.call(getTaskResultReq).failIfNotSuccessful();
Ce.Task task = parseCeTaskResponse(getTaskResultResponse);
if (TASK_TERMINAL_STATUSES.contains(task.getStatus())) {
return task;
}
Thread.sleep(POLLING_INTERVAL_IN_MS);
currentTime += POLLING_INTERVAL_IN_MS;
} catch (HttpException e) {
throw MessageException.of(String.format("Failed to get CE Task status - %s", DefaultScannerWsClient.createErrorMessage(e)));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Quality Gate check has been interrupted", e);
}
}
throw MessageException.of("Quality Gate check timeout exceeded - View details on " + ceTaskReportDataHolder.getDashboardUrl());
}
use of org.sonarqube.ws.client.HttpException in project sonarqube by SonarSource.
the class ReportPublisher method upload.
/**
* Uploads the report file to server and returns the generated task id
*/
String upload(File report) {
LOG.debug("Upload report");
long startTime = System.currentTimeMillis();
PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
PostRequest post = new PostRequest("api/ce/submit").setMediaType(MediaTypes.PROTOBUF).setParam("projectKey", moduleHierarchy.root().key()).setParam("projectName", moduleHierarchy.root().getOriginalName()).setPart("report", filePart);
String branchName = branchConfiguration.branchName();
if (branchName != null) {
if (branchConfiguration.branchType() != PULL_REQUEST) {
post.setParam(CHARACTERISTIC, "branch=" + branchName);
post.setParam(CHARACTERISTIC, "branchType=" + branchConfiguration.branchType().name());
} else {
post.setParam(CHARACTERISTIC, "pullRequest=" + branchConfiguration.pullRequestKey());
}
}
WsResponse response;
try {
post.setWriteTimeOutInMs(DEFAULT_WRITE_TIMEOUT);
response = wsClient.call(post);
} catch (Exception e) {
throw new IllegalStateException("Failed to upload report: " + e.getMessage(), e);
}
try {
response.failIfNotSuccessful();
} catch (HttpException e) {
throw MessageException.of(String.format("Server failed to process report. Please check server logs: %s", DefaultScannerWsClient.createErrorMessage(e)));
}
try (InputStream protobuf = response.contentStream()) {
return Ce.SubmitResponse.parser().parseFrom(protobuf).getTaskId();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
long stopTime = System.currentTimeMillis();
LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms");
}
}
use of org.sonarqube.ws.client.HttpException in project sonarqube by SonarSource.
the class DefaultProjectRepositoriesLoaderTest method failFastHttpErrorMessageException.
@Test
public void failFastHttpErrorMessageException() {
HttpException http = new HttpException("uri", 403, null);
MessageException e = MessageException.of("http error", http);
WsTestUtil.mockException(wsClient, e);
assertThatThrownBy(() -> loader.load(PROJECT_KEY, null)).isInstanceOf(MessageException.class).hasMessage("http error");
}
Aggregations