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);
}
Aggregations