org.springframework.batch.core.configuration.DuplicateJobException Java Examples

The following examples show how to use org.springframework.batch.core.configuration.DuplicateJobException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResponseExceptionHandler.java    From spring-batch-rest with Apache License 2.0 6 votes vote down vote up
@ExceptionHandler(BatchRuntimeException.class)
protected ResponseEntity<Object> handleBatchRuntimeException(BatchRuntimeException e, WebRequest request) {
    log.error("Request {} failed with {}", request, e);
    Throwable cause = e.getCause();
    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    if (cause instanceof DuplicateJobException
            || cause instanceof JobExecutionAlreadyRunningException
            || cause instanceof JobInstanceAlreadyCompleteException)
        status = HttpStatus.CONFLICT;
    else if (cause instanceof JobParametersInvalidException
        || cause instanceof JobParametersNotFoundException)
        status = HttpStatus.BAD_REQUEST;
    else if (cause instanceof NoSuchJobException
        || cause instanceof NoSuchJobExecutionException
        || cause instanceof NoSuchJobInstanceException)
        status = HttpStatus.NOT_FOUND;

    ApiError apiError = new ApiError(status.toString(), cause.getMessage(), cause.getClass().getSimpleName(), e.getMessage());
    return handleExceptionInternal(e, apiError, new HttpHeaders(), status, request);
}
 
Example #2
Source File: CustomJsrJobOperator.java    From spring-boot-starter-batch-web with Apache License 2.0 5 votes vote down vote up
public void register(Job job, org.springframework.batch.core.JobExecution jobExecution)
		throws DuplicateJobException {

	if (registry.containsKey(jobExecution.getId())) {
		throw new DuplicateJobException("This job execution has already been registered");
	} else {
		registry.put(jobExecution.getId(), job);
	}
}
 
Example #3
Source File: JobExecutionControllerTest.java    From spring-batch-rest with Apache License 2.0 4 votes vote down vote up
@Test
public void jobFailsWithDuplicateJobException() throws Exception {
    assertJobExecutionExceptionToStatusMapping(new DuplicateJobException("causeMsg"), HttpStatus.CONFLICT);
}