Skip to content

Commit

Permalink
Ensure that RESTEasy Reactive violation report doesn't break Hibernat…
Browse files Browse the repository at this point in the history
…e Validator in native

Fixes: quarkusio#21516
(cherry picked from commit 34648ed)
  • Loading branch information
geoand authored and gsmet committed Nov 24, 2021
1 parent c84fb59 commit 8effd1f
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'' +
'}';
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
}

0 comments on commit 8effd1f

Please sign in to comment.