public void init() { before("/*", (request, response) -> request.attribute(TIMER_START, new RuntimeHeaderEmitter(request, response))); before("/*", (request, response) -> response.header("Cache-Control", "max-age=0, private, must-revalidate")); controllers.forEach(SparkSpringController::setupRoutes); sparkControllers.forEach(SparkController::setupRoutes); exception(JsonParseException.class, this::invalidJsonPayload); exception(UnprocessableEntityException.class, this::unprocessableEntity); afterAfter("/*", (request, response) -> request.<RuntimeHeaderEmitter>attribute(TIMER_START).render()); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", this::setContentType); before("/*", this::setContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserOrGroupAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAdminUserOrGroupAdminUserAnd403); get(Routes.ElasticProfileAPI.ID + Routes.ElasticProfileAPI.USAGES, mimeType, this::usages); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before(Export.PIPELINES_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupAdminUserAnd403); get(Export.PIPELINES_PATH, mimeType, this::exportPipeline); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); get("", mimeType, this::index); post("", mimeType, this::create); get(Routes.Roles.NAME_PATH, mimeType, this::show); put(Routes.Roles.NAME_PATH, mimeType, this::update); delete(Routes.Roles.NAME_PATH, mimeType, this::destroy); exception(InvalidPluginTypeException.class, (ex, req, res) -> { res.body(this.messageJson(ex)); res.status(HttpStatus.BAD_REQUEST.value()); }); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(Routes.BuildCause.PATH), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", mimeType, apiAuthenticationHelper::checkPipelineViewPermissionsAnd403); before("/*", mimeType, apiAuthenticationHelper::checkPipelineViewPermissionsAnd403); before("", this::verifyContentType); before("/*", this::verifyContentType); get("", mimeType, this::index); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); get("", mimeType, this::index); post("", mimeType, this::create); patch("", mimeType, this::bulkUpdate); get(Routes.Roles.NAME_PATH, mimeType, this::show); put(Routes.Roles.NAME_PATH, mimeType, this::update); delete(Routes.Roles.NAME_PATH, mimeType, this::destroy); exception(InvalidPluginTypeException.class, (ex, req, res) -> { res.body(this.messageJson(ex)); res.status(HttpStatus.BAD_REQUEST.value()); }); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before(Routes.Pipeline.PAUSE_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Pipeline.UNPAUSE_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Pipeline.UNLOCK_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Pipeline.TRIGGER_OPTIONS_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Pipeline.SCHEDULE_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); post(Routes.Pipeline.PAUSE_PATH, mimeType, this::pause); post(Routes.Pipeline.UNPAUSE_PATH, mimeType, this::unpause); post(Routes.Pipeline.UNLOCK_PATH, mimeType, this::unlock); get(Routes.Pipeline.TRIGGER_OPTIONS_PATH, mimeType, this::triggerOptions); post(Routes.Pipeline.SCHEDULE_PATH, mimeType, this::schedule); exception(RecordNotFoundException.class, this::notFound); exception(InvalidGoCipherTextRuntimeException.class, (InvalidGoCipherTextRuntimeException exception, Request request, Response response) -> { response.status(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.body(MessageJson.create(HaltApiMessages.errorWhileEncryptingMessage())); }); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before("", mimeType, apiAuthenticationHelper::checkAnyAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAnyAdminUserAnd403); before("", mimeType, this::checkRateLimitAvailable); post("", mimeType, this::encrypt); exception(CryptoException.class, (CryptoException exception, Request request, Response response) -> { response.status(HttpStatus.INTERNAL_SERVER_ERROR.value()); response.body(MessageJson.create(HaltApiMessages.errorWhileEncryptingMessage())); }); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", this::setContentType); before("/*", this::setContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); get("", this::index); get(Routes.ArtifactStoreConfig.ID, this::show); post("", this::create); put(Routes.ArtifactStoreConfig.ID, this::update); delete(Routes.ArtifactStoreConfig.ID, this::destroy); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", this::setContentType); before("/*", this::setContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserOrGroupAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAdminUserOrGroupAdminUserAnd403); get("", mimeType, this::index); get(Routes.ElasticProfileAPI.ID, mimeType, this::show); post("", mimeType, this::create); put(Routes.ElasticProfileAPI.ID, mimeType, this::update); delete(Routes.ElasticProfileAPI.ID, mimeType, this::destroy); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", this::setContentType); before("/*", this::setContentType); before("", mimeType, this::checkSecurityOr403); before("/*", mimeType, this::checkSecurityOr403); get("", mimeType, this::index); get(Routes.AgentsAPI.UUID, mimeType, this::show); patch(Routes.AgentsAPI.UUID, mimeType, this::update); patch("", mimeType, this::bulkUpdate); delete(Routes.AgentsAPI.UUID, mimeType, this::deleteAgent); delete("", mimeType, this::bulkDeleteAgents); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before(Routes.MaintenanceMode.ENABLE, mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before(Routes.MaintenanceMode.DISABLE, mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before(Routes.MaintenanceMode.INFO, mimeType, apiAuthenticationHelper::checkAdminUserAnd403); post(Routes.MaintenanceMode.ENABLE, mimeType, this::enableMaintenanceModeState); post(Routes.MaintenanceMode.DISABLE, mimeType, this::disableMaintenanceModeState); get(Routes.MaintenanceMode.INFO, mimeType, this::getMaintenanceModeInfo); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", this::setContentType); before("/*", this::setContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before("/*", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); get("", mimeType, this::index); get(Routes.Environments.NAME, mimeType, this::show); post("", mimeType, this::create); put(Routes.Environments.NAME, mimeType, this::update); patch(Routes.Environments.NAME, this::partialUpdate); delete(Routes.Environments.NAME, this::remove); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before("", mimeType, apiAuthenticationHelper::checkPipelineCreationAuthorizationAnd403); before(Routes.PipelineConfig.NAME, mimeType, apiAuthenticationHelper::checkPipelineGroupAdminUserAnd403); post("", mimeType, this::create); get(Routes.PipelineConfig.NAME, mimeType, this::show); put(Routes.PipelineConfig.NAME, mimeType, this::update); delete(Routes.PipelineConfig.NAME, mimeType, this::destroy); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before("", mimeType, apiAuthenticationHelper::checkAdminUserAnd403); before(Routes.PipelineGroupsAdmin.NAME_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupAdminUserAnd403); get("", mimeType, this::index); post("", mimeType, this::create); get(Routes.PipelineGroupsAdmin.NAME_PATH, mimeType, this::show); put(Routes.PipelineGroupsAdmin.NAME_PATH, mimeType, this::update); delete(Routes.PipelineGroupsAdmin.NAME_PATH, mimeType, this::destroy); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerBasePath(), () -> { before("", mimeType, this::setContentType); before("", mimeType, authHelper::checkAdminUserAnd403); before("", this::verifyContentType); before("/*", mimeType, this::setContentType); before("/*", mimeType, authHelper::checkAdminUserAnd403); before("/*", this::verifyContentType); get(ConfigRepos.INDEX_PATH, mimeType, this::index); get(ConfigRepos.REPO_PATH, mimeType, this::showRepo); post(ConfigRepos.CREATE_PATH, mimeType, this::createRepo); put(ConfigRepos.UPDATE_PATH, mimeType, this::updateRepo); delete(ConfigRepos.DELETE_PATH, mimeType, this::deleteRepo); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before(Routes.Stage.TRIGGER_STAGE_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Stage.TRIGGER_FAILED_JOBS_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Stage.TRIGGER_SELECTED_JOBS_PATH, mimeType, apiAuthenticationHelper::checkPipelineGroupOperateUserAnd403); before(Routes.Stage.INSTANCE_BY_COUNTER, mimeType, apiAuthenticationHelper::checkPipelineViewPermissionsAnd403); post(Routes.Stage.TRIGGER_STAGE_PATH, mimeType, this::triggerStage); post(Routes.Stage.TRIGGER_FAILED_JOBS_PATH, mimeType, this::rerunFailedJobs); post(Routes.Stage.TRIGGER_SELECTED_JOBS_PATH, mimeType, this::rerunSelectedJobs); get(Routes.Stage.INSTANCE_BY_COUNTER, mimeType, this::instanceByCounter); exception(RecordNotFoundException.class, this::notFound); }); }
@Override public void setupRoutes() { path(controllerPath(), () -> { before("", mimeType, this::setContentType); before("/*", mimeType, this::setContentType); before("", this::verifyContentType); before("/*", this::verifyContentType); before("", mimeType, onlyOn(apiAuthenticationHelper::checkAdminUserOrGroupAdminUserAnd403, "POST")); before("", mimeType, onlyOn(apiAuthenticationHelper::checkViewAccessToTemplateAnd403, "GET", "HEAD")); before(Routes.PipelineTemplateConfig.NAME, mimeType, onlyOn(apiAuthenticationHelper::checkViewAccessToTemplateAnd403, "GET", "HEAD")); before(Routes.PipelineTemplateConfig.NAME, mimeType, onlyOn(apiAuthenticationHelper::checkAdminOrTemplateAdminAnd403, "PUT", "PATCH", "DELETE")); get("", mimeType, this::index); post("", mimeType, this::create); get(Routes.PipelineTemplateConfig.NAME, mimeType, this::show); put(Routes.PipelineTemplateConfig.NAME, mimeType, this::update); delete(Routes.PipelineTemplateConfig.NAME, mimeType, this::destroy); exception(RecordNotFoundException.class, this::notFound); }); }
public static void main(String[] args) { post("/query", RestServer::processBasicBatchQuery, RestServer::toJsonString); exception(Exception.class, (exception, request, response) -> { log.error("An exception occurred: ", exception); }); }
/** * Creates a controller that maps requests to actions. */ public UserController(final UserService userService) { Spark.staticFileLocation("/public"); get("/api/users", (req, res) -> userService.getAllUsers(), json()); get("/api/users/:id", (req, res) -> userService.getUser(req.params(":id")), json()); post("/api/users", (req, res) -> userService.createUser(req.queryParams("name"), req.queryParams("email")), json()); put("/api/users/:id", (req, res) -> userService.updateUser( req.params(":id"), req.queryParams("name"), req.queryParams("email") ), json()); delete("/api/users/:id", (req, res) -> userService.deleteUser(req.params(":id")), json()); after((req, res) -> { res.type("application/json"); }); exception(IllegalArgumentException.class, (error, req, res) -> { res.status(400); res.body(toJson(new ResponseError(error))); }); }