use of org.sonar.server.exceptions.ForbiddenException in project sonarqube by SonarSource.
the class QualityGateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
response.setHeader("Cache-Control", "no-cache");
response.stream().setMediaType(SVG);
try (DbSession dbSession = dbClient.openSession(false)) {
support.validateToken(request);
BranchDto branch = support.getBranch(dbSession, request);
Level qualityGateStatus = getQualityGate(dbSession, branch);
String result = svgGenerator.generateQualityGate(qualityGateStatus);
String eTag = getETag(result);
Optional<String> requestedETag = request.header("If-None-Match");
if (requestedETag.filter(eTag::equals).isPresent()) {
response.stream().setStatus(304);
return;
}
response.setHeader("ETag", eTag);
write(result, response.stream().output(), UTF_8);
} catch (ProjectBadgesException | ForbiddenException | NotFoundException e) {
// There is an issue, so do not return any ETag but make this response expire now
SimpleDateFormat sdf = new SimpleDateFormat(RFC1123_DATE, Locale.US);
response.setHeader("Expires", sdf.format(new Date()));
write(svgGenerator.generateError(e.getMessage()), response.stream().output(), UTF_8);
}
}
Aggregations