Search in sources :

Example 1 with ResponseConstraintViolationException

use of org.apache.cxf.validation.ResponseConstraintViolationException in project cxf by apache.

the class ValidationExceptionMapper method toResponse.

@Override
public Response toResponse(ValidationException exception) {
    Response.Status errorStatus = Response.Status.INTERNAL_SERVER_ERROR;
    if (exception instanceof ConstraintViolationException) {
        StringBuilder responseBody = addMessageToResponse ? new StringBuilder() : null;
        final ConstraintViolationException constraint = (ConstraintViolationException) exception;
        for (final ConstraintViolation<?> violation : constraint.getConstraintViolations()) {
            String message = buildErrorMessage(violation);
            if (responseBody != null) {
                responseBody.append(message).append('\n');
            }
            LOG.log(Level.WARNING, message);
        }
        if (!(constraint instanceof ResponseConstraintViolationException)) {
            errorStatus = Response.Status.BAD_REQUEST;
        }
        return buildResponse(errorStatus, responseBody != null ? responseBody.toString() : null);
    }
    return buildResponse(errorStatus, addMessageToResponse ? exception.getMessage() : null);
}
Also used : Response(javax.ws.rs.core.Response) ResponseConstraintViolationException(org.apache.cxf.validation.ResponseConstraintViolationException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponseConstraintViolationException(org.apache.cxf.validation.ResponseConstraintViolationException)

Aggregations

ConstraintViolationException (javax.validation.ConstraintViolationException)1 Response (javax.ws.rs.core.Response)1 ResponseConstraintViolationException (org.apache.cxf.validation.ResponseConstraintViolationException)1