From 8effd1f7cda7344abdc72a513c5c2fde3d622349 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis <geoand@gmail.com> Date: Tue, 23 Nov 2021 10:59:24 +0200 Subject: [PATCH] Ensure that RESTEasy Reactive violation report doesn't break Hibernate Validator in native Fixes: #21516 (cherry picked from commit 34648edf85a05a42e433afe6cd195bc1e6d865ff) --- .../HibernateValidatorProcessor.java | 5 +- ...teasyReactiveViolationExceptionMapper.java | 95 ---------------- .../runtime/jaxrs/ViolationReport.java | 101 ++++++++++++++++++ 3 files changed, 104 insertions(+), 97 deletions(-) create mode 100644 extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ViolationReport.java diff --git a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java index 41ae49a227b3d..81d69df34b422 100644 --- a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java +++ b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java @@ -78,6 +78,7 @@ import io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor; import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyConfigSupport; import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyReactiveViolationExceptionMapper; +import io.quarkus.hibernate.validator.runtime.jaxrs.ViolationReport; import io.quarkus.hibernate.validator.spi.BeanValidationAnnotationsBuildItem; import io.quarkus.jaxrs.spi.deployment.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.resteasy.common.spi.ResteasyConfigBuildItem; @@ -357,8 +358,8 @@ void exceptionMapper(BuildProducer<ExceptionMapperBuildItem> exceptionMapperProd exceptionMapperProducer.produce(new ExceptionMapperBuildItem(ResteasyReactiveViolationExceptionMapper.class.getName(), ValidationException.class.getName(), Priorities.USER + 1, true)); reflectiveClassProducer.produce( - new ReflectiveClassBuildItem(true, true, ResteasyReactiveViolationExceptionMapper.ViolationReport.class, - ResteasyReactiveViolationExceptionMapper.ViolationReport.Violation.class)); + new ReflectiveClassBuildItem(true, true, ViolationReport.class, + ViolationReport.Violation.class)); } private static void contributeBuiltinConstraints(Set<String> builtinConstraints, diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveViolationExceptionMapper.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveViolationExceptionMapper.java index 3c349106d48dc..ec3f4912b1f69 100644 --- a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveViolationExceptionMapper.java +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveViolationExceptionMapper.java @@ -87,99 +87,4 @@ private Response buildViolationReportResponse(ConstraintViolationException cve) return builder.build(); } - /** - * As spec doesn't say anything about the report format, - * we just use https://opensource.zalando.com/problem/constraint-violation - * This also what Reactive Routes uses - */ - public static class ViolationReport { - private String title; - private int status; - private List<Violation> violations; - - /** - * Requires no-args constructor for some serializers. - */ - public ViolationReport() { - } - - public ViolationReport(String title, Status status, List<Violation> violations) { - this.title = title; - this.status = status.getStatusCode(); - this.violations = violations; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public int getStatus() { - return status; - } - - public void setStatus(int status) { - this.status = status; - } - - public List<Violation> getViolations() { - return violations; - } - - public void setViolations(List<Violation> violations) { - this.violations = violations; - } - - @Override - public String toString() { - return "ViolationReport{" + - "title='" + title + '\'' + - ", status=" + status + - ", violations=" + violations + - '}'; - } - - public static class Violation { - private String field; - private String message; - - /** - * Requires no-args constructor for some serializers. - */ - public Violation() { - } - - public Violation(String field, String message) { - this.field = field; - this.message = message; - } - - public String getField() { - return field; - } - - public void setField(String field) { - this.field = field; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Override - public String toString() { - return "Violation{" + - "field='" + field + '\'' + - ", message='" + message + '\'' + - '}'; - } - } - } } diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ViolationReport.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ViolationReport.java new file mode 100644 index 0000000000000..ab3955ddcac0c --- /dev/null +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ViolationReport.java @@ -0,0 +1,101 @@ +package io.quarkus.hibernate.validator.runtime.jaxrs; + +import java.util.List; + +import javax.ws.rs.core.Response; + +/** + * As spec doesn't say anything about the report format, + * we just use https://opensource.zalando.com/problem/constraint-violation + * This also what Reactive Routes uses + */ +public class ViolationReport { + private String title; + private int status; + private List<Violation> violations; + + /** + * Requires no-args constructor for some serializers. + */ + public ViolationReport() { + } + + public ViolationReport(String title, Response.Status status, List<Violation> violations) { + this.title = title; + this.status = status.getStatusCode(); + this.violations = violations; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public List<Violation> getViolations() { + return violations; + } + + public void setViolations(List<Violation> violations) { + this.violations = violations; + } + + @Override + public String toString() { + return "ViolationReport{" + + "title='" + title + '\'' + + ", status=" + status + + ", violations=" + violations + + '}'; + } + + public static class Violation { + private String field; + private String message; + + /** + * Requires no-args constructor for some serializers. + */ + public Violation() { + } + + public Violation(String field, String message) { + this.field = field; + this.message = message; + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "Violation{" + + "field='" + field + '\'' + + ", message='" + message + '\'' + + '}'; + } + } +}