javax.validation.ConstraintDeclarationException#org.jboss.resteasy.api.validation.ResteasyViolationException源码实例Demo

下面列出了javax.validation.ConstraintDeclarationException#org.jboss.resteasy.api.validation.ResteasyViolationException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public Response toResponse(ValidationException exception) {
    if (exception instanceof ConstraintDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ConstraintDeclarationException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof GroupDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ResteasyViolationException) {
        ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
        Exception e = resteasyViolationException.getException();
        if (e != null) {
            return buildResponse(unwrapException(e), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
        } else if (resteasyViolationException.getReturnValueViolations().size() == 0) {
            return buildViolationReportResponse(resteasyViolationException, Status.BAD_REQUEST);
        } else {
            return buildViolationReportResponse(resteasyViolationException, Status.INTERNAL_SERVER_ERROR);
        }
    }
    return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
 
protected Response buildViolationReportResponse(ResteasyViolationException exception, Status status) {
    ResponseBuilder builder = Response.status(status);
    builder.header(Validation.VALIDATION_HEADER, "true");

    // Check standard media types.
    MediaType mediaType = getAcceptMediaType(exception.getAccept());
    if (mediaType != null) {
        builder.type(mediaType);
        builder.entity(new ViolationReport(exception));
        return builder.build();
    }

    // Default media type.
    builder.type(MediaType.TEXT_PLAIN);
    builder.entity(exception.toString());
    return builder.build();
}
 
源代码3 项目: gossip   文件: GossipValidateErrorProvider.java
private Response buildViolationReportResponse(ResteasyViolationException exception) {
    ResponseBuilder builder = Response.status(BAD_REQUEST);
    builder.header(VALIDATION_HEADER, "true");
    builder.type(APPLICATION_JSON_TYPE);

    List<ResteasyConstraintViolation> violations = exception.getViolations();

    if (violations.isEmpty()) {
        builder.entity(new ValidateErrorResponse(exception.toString()));
    } else {
        if (log.isDebugEnabled()) {
            try {
                log.debug(objectMapper.writeValueAsString(violations));
            } catch (JsonProcessingException e) {
                log.debug("", e); // Useless, just make sonar and compiler happy w(゚Д゚)w
            }
        }
        builder.entity(new ValidateErrorResponse(violations));
    }

    return builder.build();
}
 
@Override
public Response toResponse(ValidationException exception) {
    if (exception instanceof ConstraintDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ConstraintDeclarationException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof GroupDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ResteasyViolationException) {
        ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
        Exception e = resteasyViolationException.getException();
        if (e != null) {
            return buildResponse(unwrapException(e), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
        } else if (resteasyViolationException.getReturnValueViolations().size() == 0) {
            return buildViolationReportResponse(resteasyViolationException, Status.BAD_REQUEST);
        } else {
            return buildViolationReportResponse(resteasyViolationException, Status.INTERNAL_SERVER_ERROR);
        }
    }
    return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
 
protected Response buildViolationReportResponse(ResteasyViolationException exception, Status status) {
    ResponseBuilder builder = Response.status(status);
    builder.header(Validation.VALIDATION_HEADER, "true");

    // Check standard media types.
    MediaType mediaType = getAcceptMediaType(exception.getAccept());
    if (mediaType != null) {
        builder.type(mediaType);
        builder.entity(new ViolationReport(exception));
        return builder.build();
    }

    // Default media type.
    builder.type(MediaType.TEXT_PLAIN);
    builder.entity(exception.toString());
    return builder.build();
}
 
源代码6 项目: gossip   文件: GossipValidateErrorProvider.java
@Override
public Response toResponse(ValidationException exception) {
    if (exception instanceof ResteasyViolationException) {
        ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
        Exception e = resteasyViolationException.getException();
        if (e == null) {
            return buildViolationReportResponse(resteasyViolationException);
        }
    }

    // Common response
    return exceptionResponse(exception);
}
 
@Override
protected List<ValidationErrorXO> getValidationErrors(final ResteasyViolationException exception) {
  return getValidationErrors(exception.getViolations());
}
 
@Override
protected Status getStatus(final ResteasyViolationException exception) {
  return getResponseStatus(exception.getViolations());
}