Java 类org.glassfish.jersey.server.validation.internal.ValidationHelper 实例源码

项目:jim    文件:ImValidationExceptionMapper.java   
@Override
public Response toResponse(ValidationException e) {
    ApiErrorCode errorCode = ApiErrorCode.PARAM_ERROR;

    StringBuffer errorMsgBuf = new StringBuffer();

    final ConstraintViolationException cve = (ConstraintViolationException) e;
    List<ValidationError> errors = ValidationHelper.constraintViolationToValidationErrors(cve);
    for (ValidationError error : errors) {
        errorMsgBuf.append(error.getMessage()).append(";");
    }

    String errorMsg = errorMsgBuf.toString();
    if (StringUtils.isBlank(errorMsg)) {
        errorMsg = IMConstant.MSG_PARAM_ERROR;
    }        

    String requestId = RequestContext.get("requestId");

    ApiErrorCodeException errorCodeException = new ApiErrorCodeException(requestId, errorCode, errorMsg, e);
    logger.error(requestId, errorCodeException);

    return RestResult.failure(requestId, errorCode.errorCode, errorMsg);
}
项目:git-webapp    文件:AjaxValidationErrorExceptionMapper.java   
@Override
public Response toResponse(ConstraintViolationException exception) {
  ValidationErrorResult result = new ValidationErrorResult();

  for (ConstraintViolation<?> v : exception.getConstraintViolations()) {
    String paramName = ConstraintUtils.paramName(v);
    result.addError(paramName, v.getMessage());
  }
  return Response.status(ValidationHelper.getResponseStatus(exception))
      .type(MediaType.APPLICATION_JSON)
      .entity(result)
      .build();
}
项目:parsec-libraries    文件:ParsecValidationExceptionMapper.java   
/**
 * implement toResponse with code, message.
 *
 * @param e the validation exception object
 * @param code the code
 * @param message the message
 *
 * @return the response
 */
private Response toResponse(ConstraintViolationException e, int code, String message) {
    LOGGER.log(Level.FINER, LocalizationMessages.CONSTRAINT_VIOLATIONS_ENCOUNTERED(), e);
    List<ValidationError> errors = ValidationHelper.constraintViolationToValidationErrors(e);
    ParsecErrorResponse<ValidationError> errorResponse = ValidateUtil.buildErrorResponse(errors, code, message);
    return Response.status(Response.Status.BAD_REQUEST)
            .entity(new GenericEntity<ParsecErrorResponse<ValidationError>>(errorResponse) { }).build();
}