Search in sources :

Example 1 with JpaSystemException

use of org.springframework.orm.jpa.JpaSystemException in project syncope by apache.

the class RestServiceExceptionMapper method toResponse.

@Override
public Response toResponse(final Exception ex) {
    LOG.error("Exception thrown", ex);
    ResponseBuilder builder;
    if (ex instanceof AccessDeniedException) {
        // leaves the default exception processing to Spring Security
        builder = null;
    } else if (ex instanceof SyncopeClientException) {
        SyncopeClientException sce = (SyncopeClientException) ex;
        builder = sce.isComposite() ? getSyncopeClientCompositeExceptionResponse(sce.asComposite()) : getSyncopeClientExceptionResponse(sce);
    } else if (ex instanceof DelegatedAdministrationException || ExceptionUtils.getRootCause(ex) instanceof DelegatedAdministrationException) {
        builder = builder(ClientExceptionType.DelegatedAdministration, ExceptionUtils.getRootCauseMessage(ex));
    } else if (ex instanceof EntityExistsException || ex instanceof DuplicateException || ex instanceof PersistenceException && ex.getCause() instanceof EntityExistsException) {
        builder = builder(ClientExceptionType.EntityExists, getJPAMessage(ex instanceof PersistenceException ? ex.getCause() : ex));
    } else if (ex instanceof DataIntegrityViolationException || ex instanceof JpaSystemException) {
        builder = builder(ClientExceptionType.DataIntegrityViolation, getJPAMessage(ex));
    } else if (ex instanceof ConnectorException) {
        builder = builder(ClientExceptionType.ConnectorException, ExceptionUtils.getRootCauseMessage(ex));
    } else if (ex instanceof NotFoundException) {
        builder = builder(ClientExceptionType.NotFound, ExceptionUtils.getRootCauseMessage(ex));
    } else {
        builder = processInvalidEntityExceptions(ex);
        if (builder == null) {
            builder = processBadRequestExceptions(ex);
        }
        // process JAX-RS validation errors
        if (builder == null && ex instanceof ValidationException) {
            builder = builder(validationEM.toResponse((ValidationException) ex)).header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.name()).header(RESTHeaders.ERROR_INFO, ClientExceptionType.RESTValidation.getInfoHeaderValue(ExceptionUtils.getRootCauseMessage(ex)));
            ErrorTO error = new ErrorTO();
            error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode());
            error.setType(ClientExceptionType.RESTValidation);
            error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
            builder.entity(error);
        }
        // ...or just report as InternalServerError
        if (builder == null) {
            builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).header(RESTHeaders.ERROR_INFO, ClientExceptionType.Unknown.getInfoHeaderValue(ExceptionUtils.getRootCauseMessage(ex)));
            ErrorTO error = new ErrorTO();
            error.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
            error.setType(ClientExceptionType.Unknown);
            error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
            builder.entity(error);
        }
    }
    return builder == null ? null : builder.build();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) ValidationException(javax.validation.ValidationException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) EntityExistsException(javax.persistence.EntityExistsException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) JpaSystemException(org.springframework.orm.jpa.JpaSystemException) ErrorTO(org.apache.syncope.common.lib.to.ErrorTO) DuplicateException(org.apache.syncope.core.persistence.api.dao.DuplicateException) ConnectorException(org.identityconnectors.framework.common.exceptions.ConnectorException) PersistenceException(javax.persistence.PersistenceException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder)

Aggregations

EntityExistsException (javax.persistence.EntityExistsException)1 PersistenceException (javax.persistence.PersistenceException)1 ValidationException (javax.validation.ValidationException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 ErrorTO (org.apache.syncope.common.lib.to.ErrorTO)1 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)1 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)1 ConnectorException (org.identityconnectors.framework.common.exceptions.ConnectorException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 JpaSystemException (org.springframework.orm.jpa.JpaSystemException)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1