Search in sources :

Example 96 with ResponseEntity

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 97 with ResponseEntity

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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 98 with ResponseEntity

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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 99 with ResponseEntity

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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 100 with ResponseEntity

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);
}
Also used : RestApiErrorResult(com.vip.saturn.job.console.domain.RestApiErrorResult) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity)

Aggregations

ResponseEntity (org.springframework.http.ResponseEntity)1188 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)419 HttpHeaders (org.springframework.http.HttpHeaders)398 Test (org.junit.Test)120 ApiOperation (io.swagger.annotations.ApiOperation)116 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)108 HashMap (java.util.HashMap)104 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)98 HttpStatus (org.springframework.http.HttpStatus)88 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)85 ArrayList (java.util.ArrayList)80 GetMapping (org.springframework.web.bind.annotation.GetMapping)79 Timed (com.codahale.metrics.annotation.Timed)68 IOException (java.io.IOException)67 List (java.util.List)65 URI (java.net.URI)49 MediaType (org.springframework.http.MediaType)48 Test (org.junit.jupiter.api.Test)46 HttpEntity (org.springframework.http.HttpEntity)46