in amazon-sns-trigger-server/src/main/java/jetbrains/buildServer/clouds/amazon/sns/trigger/controllers/AwsSnsHttpEndpointController.java [58:119]
protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception {
final ActionErrors errors = new ActionErrors();
try {
final String fullPath = request.getServletPath() + request.getPathInfo();
Matcher m = pathPattern.matcher(fullPath);
if (!m.find()) {
throw new AwsSnsHttpEndpointException("Invalid or Unsupported URL is given: " + fullPath);
}
String projectId = m.group(1);
String buildTypeId = m.group(2);
String triggerUuid = m.group(3);
if (projectId == null || projectId.trim().isEmpty()) {
throw new AwsSnsHttpEndpointException("No ProjectId given in the path");
}
if (buildTypeId == null || buildTypeId.trim().isEmpty()) {
throw new AwsSnsHttpEndpointException("No BuildTypeId given in the path");
}
if (triggerUuid == null || triggerUuid.trim().isEmpty()) {
throw new AwsSnsHttpEndpointException("No Trigger UUID given in the path");
}
String finalProjectId = projectId.trim();
final String finalBuildTypeId = buildTypeId.trim();
SProject project = mySecurityContext.runAsSystemUnchecked(() -> myProjectManager.findProjectByExternalId(finalProjectId));
if (project == null) {
throw new AwsSnsHttpEndpointException("Couldn't find the project with id: " + finalProjectId);
}
SBuildType buildType = mySecurityContext.runAsSystemUnchecked(() -> project.findBuildTypeByExternalId(finalBuildTypeId));
if (buildType == null) {
throw new AwsSnsHttpEndpointException("Couldn't find build type with id: " + finalBuildTypeId);
}
final String finalTriggerUuid = triggerUuid.trim();
BuildTriggerDescriptor buildTrigger = buildType.getBuildTriggersCollection().stream()
.filter(btd -> btd.getType().equals(TRIGGER_NAME) &&
btd.getProperties().get(AwsSnsTriggerConstants.TRIGGER_UUID_PROPERTY_KEY) != null &&
btd.getProperties().get(AwsSnsTriggerConstants.TRIGGER_UUID_PROPERTY_KEY).equals(finalTriggerUuid))
.findFirst()
.orElseThrow(() -> new AwsSnsHttpEndpointException("There are no suitable trigger in the build: " + finalBuildTypeId));
// OK! we've defined project and the buildType with necessary buildTrigger
// lets get into request details and find out what kind of request is it?
if (isPost(request)) {
doPost(request, buildType, buildTrigger);
}
// otherwise just ignore this message
} catch (Exception error) {
LOG.warnAndDebugDetails("Error while processing SNS Endpoint request", error);
errors.addError("error_snsEndpointResolve", error.getMessage());
writeErrorsAsJson(errors, response);
}
// this will return HTTP_CODE 200
return null;
}