use of org.springframework.http.ResponseEntity in project Saturn by vipshop.
the class JobOperationRestApiController method updateJobCron.
@RequestMapping(value = { "/{namespace}/{jobName}/cron", "/{namespace}/jobs/{jobName}/cron" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> updateJobCron(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName, @RequestBody Map<String, String> params, HttpServletRequest request) throws SaturnJobConsoleException {
HttpHeaders httpHeaders = new HttpHeaders();
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
String cron = params.remove("cron");
checkMissingParameter("cron", cron);
restApiService.updateJobCron(namespace, jobName, cron, params);
return new ResponseEntity<>(httpHeaders, HttpStatus.OK);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of org.springframework.http.ResponseEntity in project Saturn by vipshop.
the class JobOperationRestApiController method stop.
@RequestMapping(value = "/{namespace}/jobs/{jobName}/stop", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> stop(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
restApiService.stopJobAtOnce(namespace, jobName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of org.springframework.http.ResponseEntity in project Saturn by vipshop.
the class SaturnJobConsoleExceptionHandlerController method handleSaturnJobConsoleHttpException.
@ExceptionHandler
public ResponseEntity<Object> handleSaturnJobConsoleHttpException(SaturnJobConsoleHttpException e) {
HttpHeaders httpHeaders = new HttpHeaders();
SaturnJobConsoleHttpException saturnJobConsoleHttpException = (SaturnJobConsoleHttpException) e;
int statusCode = saturnJobConsoleHttpException.getStatusCode();
if (statusCode == HttpStatus.CREATED.value()) {
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
return constructErrorResponse(e.getMessage(), HttpStatus.valueOf(statusCode));
}
use of org.springframework.http.ResponseEntity in project Saturn by vipshop.
the class RestApiExceptionHandlerController method handleSaturnJobConsoleHttpException.
@ExceptionHandler
public ResponseEntity<Object> handleSaturnJobConsoleHttpException(SaturnJobConsoleHttpException e) {
HttpHeaders httpHeaders = new HttpHeaders();
SaturnJobConsoleHttpException saturnJobConsoleHttpException = (SaturnJobConsoleHttpException) e;
int statusCode = saturnJobConsoleHttpException.getStatusCode();
if (statusCode == HttpStatus.CREATED.value()) {
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
return constructErrorResponse(e.getMessage(), HttpStatus.valueOf(statusCode));
}
use of org.springframework.http.ResponseEntity in project Saturn by vipshop.
the class RestApiExceptionHandlerController method constructErrorResponse.
private ResponseEntity<Object> constructErrorResponse(String errorMsg, HttpStatus status) {
HttpHeaders httpHeaders = new HttpHeaders();
RestApiErrorResult restApiErrorResult = new RestApiErrorResult();
restApiErrorResult.setMessage(errorMsg);
return new ResponseEntity<Object>(restApiErrorResult, httpHeaders, status);
}
Aggregations