本文整理了Java中javax.validation.ConstraintViolationException.getMessage()
方法的一些代码示例,展示了ConstraintViolationException.getMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConstraintViolationException.getMessage()
方法的具体详情如下:
包路径:javax.validation.ConstraintViolationException
类名称:ConstraintViolationException
方法名:getMessage
暂无
代码示例来源:origin: ctripcorp/apollo
@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<Map<String, Object>> handleConstraintViolationException(
HttpServletRequest request, ConstraintViolationException ex
) {
return handleError(request, BAD_REQUEST, new BadRequestException(ex.getMessage()));
}
代码示例来源:origin: spring-projects/spring-data-rest
@JsonProperty("cause")
public String getCause() {
return cve.getMessage();
}
代码示例来源:origin: com.google.gwt/gwt-servlet
public static void serialize(SerializationStreamWriter streamWriter,
ConstraintViolationException instance) throws SerializationException {
streamWriter.writeString(instance.getMessage());
streamWriter.writeObject(instance.getConstraintViolations());
}
代码示例来源:origin: javaee/glassfish
/**
* Returns true of this Transaction can be committed on this object
*
* @param t is the transaction to commit, should be the same as the
* one passed during the join(Transaction t) call.
* @return true if the trsaction commiting would be successful
*/
public synchronized boolean canCommit(Transaction t) throws TransactionFailure {
if (!isDeleted) { // HK2-127: validate only if not marked for deletion
Set constraintViolations =
beanValidator.validate(this.getProxy(this.getProxyType()));
try {
handleValidationException(constraintViolations);
} catch (ConstraintViolationException constraintViolationException) {
throw new TransactionFailure(constraintViolationException.getMessage(), constraintViolationException);
}
}
return currentTx==t;
}
代码示例来源:origin: org.springframework.data/spring-data-rest-webmvc
@JsonProperty("cause")
public String getCause() {
return cve.getMessage();
}
代码示例来源:origin: com.haulmont.cuba/cuba-rest-api
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
public ResponseEntity<List<ConstraintViolationInfo>> handleConstraintViolation(ConstraintViolationException e) {
log.debug("ConstraintViolationException: {}, violations:\n{}", e.getMessage(), e.getConstraintViolations());
List<ConstraintViolationInfo> violationInfos = getConstraintViolationInfos(e.getConstraintViolations());
return new ResponseEntity<>(violationInfos, HttpStatus.BAD_REQUEST);
}
代码示例来源:origin: org.ligoj.bootstrap/bootstrap-core
/**
* Constructor from errors.
*
* @param validation
* validation exception containing errors.
*/
public ValidationJsonException(final ConstraintViolationException validation) {
this(validation.getMessage());
validation.getConstraintViolations()
.forEach(e -> errors.computeIfAbsent(getPropertyPath(e), k -> new ArrayList<>()).add(serializeHibernateValidationError(e)));
}
代码示例来源:origin: chillzhuang/blade-tool
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R handleError(ConstraintViolationException e) {
log.warn("参数验证失败", e.getMessage());
Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
ConstraintViolation<?> violation = violations.iterator().next();
String path = ((PathImpl) violation.getPropertyPath()).getLeafNode().getName();
String message = String.format("%s:%s", path, violation.getMessage());
return R.fail(ResultCode.PARAM_VALID_ERROR, message);
}
代码示例来源:origin: leecho/cola-cloud
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(ConstraintViolationException.class)
public Result handleValidationException(ConstraintViolationException e) {
log.error(ErrorStatus.ILLEGAL_DATA.getMessage() + ":" + e.getMessage());
List<Map<String, Object>> fields = new ArrayList<>();
for (ConstraintViolation<?> cv : e.getConstraintViolations()) {
String fieldName = ((PathImpl) cv.getPropertyPath()).getLeafNode().asString();
String message = cv.getMessage();
Map<String, Object> field = new HashMap<>();
field.put("field", fieldName);
field.put("message", message);
fields.add(field);
}
return failure(ErrorStatus.ILLEGAL_DATA, fields);
}
代码示例来源:origin: lcw2004/one
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody
public ResponseMessage<ValidError> handlerConstraintViolationException(ConstraintViolationException exception) {
ConstraintViolation violation = Exceptions.getFirstError(exception);
if (violation != null) {
logger.warn("Valid Exception:{}", violation.getMessage());
} else {
logger.warn(exception.getMessage(), exception);
}
ValidError validError = new ValidError(violation.getPropertyPath().toString(), violation.getMessage());
return Result.error(ResponseMessageCodeEnum.ERROR.getCode(), validError.getMessage(), validError);
}
代码示例来源:origin: fabric8io/fabric8-maven-plugin
private void validateIfRequired(File resourceDir, ResourceClassifier classifier)
throws MojoExecutionException, MojoFailureException {
try {
if (!skipResourceValidation) {
new ResourceValidator(resourceDir, classifier, log).validate();
}
} catch (ConstraintViolationException e) {
if (failOnValidationError) {
log.error("[[R]]" + e.getMessage() + "[[R]]");
log.error("[[R]]use \"mvn -Dfabric8.skipResourceValidation=true\" option to skip the validation[[R]]");
throw new MojoFailureException("Failed to generate fabric8 descriptor");
} else {
log.warn("[[Y]]" + e.getMessage() + "[[Y]]");
}
} catch (Throwable e) {
if (failOnValidationError) {
throw new MojoExecutionException("Failed to validate resources", e);
} else {
log.warn("Failed to validate resources: %s", e.getMessage());
}
}
}
代码示例来源:origin: jkazama/sample-boot-micro
/** BeanValidation(JSR303)の制約例外 */
@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<Map<String, String[]>> handleConstraintViolation(ConstraintViolationException e) {
log.warn(e.getMessage());
Warns warns = Warns.init();
e.getConstraintViolations().forEach((v) -> warns.add(v.getPropertyPath().toString(), v.getMessage()));
return new ErrorHolder(msg, locale(), warns.list()).result(HttpStatus.BAD_REQUEST);
}
代码示例来源:origin: net.wetheinter/gwt-user
public static void serialize(SerializationStreamWriter streamWriter,
ConstraintViolationException instance) throws SerializationException {
streamWriter.writeString(instance.getMessage());
streamWriter.writeObject(instance.getConstraintViolations());
}
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
public static void serialize(SerializationStreamWriter streamWriter,
ConstraintViolationException instance) throws SerializationException {
streamWriter.writeString(instance.getMessage());
streamWriter.writeObject(instance.getConstraintViolations());
}
代码示例来源:origin: org.fornax.cartridges/fornax-cartridges-sculptor-framework
/**
* handles Hibernate validation exception
*/
public void afterThrowing(Method m, Object[] args, Object target, ConstraintViolationException e) {
Logger log = LoggerFactory.getLogger(target.getClass());
LogMessage message = new LogMessage(mapLogCode(ValidationException.ERROR_CODE), excMessage(e));
log.debug("{}", message);
ValidationException newException = new ValidationException(e.getMessage());
newException.setLogged(true);
newException.setConstraintViolations(e.getConstraintViolations());
throw newException;
}
代码示例来源:origin: org.glassfish.hk2/config
/**
* Returns true of this Transaction can be committed on this object
*
* @param t is the transaction to commit, should be the same as the
* one passed during the join(Transaction t) call.
* @return true if the trsaction commiting would be successful
*/
public synchronized boolean canCommit(Transaction t) throws TransactionFailure {
Set constraintViolations =
beanValidator.validate(this.getProxy(this.getProxyType()));
try {
handleValidationException(constraintViolations);
} catch (ConstraintViolationException constraintViolationException) {
throw new TransactionFailure(constraintViolationException.getMessage(), constraintViolationException);
}
return currentTx==t;
}
代码示例来源:origin: org.glassfish.hk2/hk2-config
/**
* Returns true of this Transaction can be committed on this object
*
* @param t is the transaction to commit, should be the same as the
* one passed during the join(Transaction t) call.
* @return true if the trsaction commiting would be successful
*/
public synchronized boolean canCommit(Transaction t) throws TransactionFailure {
if (!isDeleted) { // HK2-127: validate only if not marked for deletion
Set constraintViolations =
beanValidator.validate(this.getProxy(this.getProxyType()));
try {
handleValidationException(constraintViolations);
} catch (ConstraintViolationException constraintViolationException) {
throw new TransactionFailure(constraintViolationException.getMessage(), constraintViolationException);
}
}
return currentTx==t;
}
代码示例来源:origin: com.sun.enterprise/config
/**
* Returns true of this Transaction can be committed on this object
*
* @param t is the transaction to commit, should be the same as the
* one passed during the join(Transaction t) call.
* @return true if the trsaction commiting would be successful
*/
public synchronized boolean canCommit(Transaction t) throws TransactionFailure {
Set constraintViolations =
beanValidator.validate(this.getProxy(this.getProxyType()));
try {
handleValidationException(constraintViolations);
} catch (ConstraintViolationException constraintViolationException) {
throw new TransactionFailure(constraintViolationException.getMessage(), constraintViolationException);
}
return currentTx==t;
}
代码示例来源:origin: eclipse-ee4j/glassfish
/**
* Returns true of this Transaction can be committed on this object
*
* @param t is the transaction to commit, should be the same as the
* one passed during the join(Transaction t) call.
* @return true if the trsaction commiting would be successful
*/
public synchronized boolean canCommit(Transaction t) throws TransactionFailure {
if (!isDeleted) { // HK2-127: validate only if not marked for deletion
Set constraintViolations =
beanValidator.validate(this.getProxy(this.getProxyType()));
try {
handleValidationException(constraintViolations);
} catch (ConstraintViolationException constraintViolationException) {
throw new TransactionFailure(constraintViolationException.getMessage(), constraintViolationException);
}
}
return currentTx==t;
}
代码示例来源:origin: io.micronaut/micronaut-validation
@Override
public HttpResponse<JsonError> handle(HttpRequest request, ConstraintViolationException exception) {
Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
if (constraintViolations == null || constraintViolations.isEmpty()) {
JsonError error = new JsonError(exception.getMessage() == null ? HttpStatus.BAD_REQUEST.getReason() : exception.getMessage());
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
} else if (constraintViolations.size() == 1) {
ConstraintViolation<?> violation = constraintViolations.iterator().next();
JsonError error = new JsonError(buildMessage(violation));
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
} else {
JsonError error = new JsonError(HttpStatus.BAD_REQUEST.getReason());
List<Resource> errors = new ArrayList<>();
for (ConstraintViolation<?> violation : constraintViolations) {
errors.add(new JsonError(buildMessage(violation)));
}
error.embedded("errors", errors);
error.link(Link.SELF, Link.of(request.getUri()));
return HttpResponse.badRequest(error);
}
}
内容来源于网络,如有侵权,请联系作者删除!