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 7e55a79e80a09..f8277aee7c77b 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 @@ -19,7 +19,9 @@ import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; +import org.jboss.resteasy.reactive.common.util.ServerMediaType; import org.jboss.resteasy.reactive.server.core.CurrentRequestManager; +import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; @Provider public class ResteasyReactiveViolationExceptionMapper implements ExceptionMapper { @@ -75,8 +77,7 @@ private Response buildViolationReportResponse(ConstraintViolationException cve) // Check standard media types. MediaType mediaType = ValidatorMediaTypeUtil.getAcceptMediaType( rrContext.getHttpHeaders().getAcceptableMediaTypes(), - rrContext.getTarget() != null ? Arrays.asList(rrContext.getTarget().getProduces().getSortedMediaTypes()) - : SUPPORTED_MEDIA_TYPES); + serverMediaTypes(rrContext)); if (mediaType == null) { mediaType = MediaType.APPLICATION_JSON_TYPE; } @@ -91,4 +92,15 @@ private Response buildViolationReportResponse(ConstraintViolationException cve) return builder.build(); } + private List serverMediaTypes(ResteasyReactiveRequestContext context) { + if (context.getTarget() == null) { + return SUPPORTED_MEDIA_TYPES; + } + ServerMediaType serverMediaType = context.getTarget().getProduces(); + if (serverMediaType == null) { + return SUPPORTED_MEDIA_TYPES; + } + return Arrays.asList(serverMediaType.getSortedMediaTypes()); + } + } diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/HibernateValidatorTestResource.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/HibernateValidatorTestResource.java index 2a9c7d6280a59..ada14f2cf6236 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/HibernateValidatorTestResource.java +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/HibernateValidatorTestResource.java @@ -19,6 +19,7 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.hibernate.validator.constraints.Length; import org.jboss.resteasy.reactive.RestPath; @@ -88,6 +89,12 @@ public String testRestEndPointWithNoProduces(@Digits(integer = 5, fraction = 0) return id; } + @GET + @Path("/no-produces-with-response/{id}/") + public Response testRestEndPointWithNoProducesUsingResponse(@Digits(integer = 5, fraction = 0) @RestPath("id") String id) { + return Response.ok(id).build(); + } + @GET @Path("/rest-end-point-return-value-validation/{returnValue}/") @Produces(MediaType.TEXT_PLAIN) diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java index 41234613bba7f..451c02b854216 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/HibernateValidatorFunctionalityTest.java @@ -169,6 +169,15 @@ public void testNoProduces() { .body(containsString("numeric value out of bounds")); } + @Test + public void testNoProducesWithResponse() { + RestAssured.given() + .get("/hibernate-validator/test/no-produces-with-response/plop/") + .then() + .statusCode(Response.Status.BAD_REQUEST.getStatusCode()) + .body(containsString("numeric value out of bounds")); + } + @Test public void testRestEndPointReturnValueValidation() { // https://github.com/quarkusio/quarkus/issues/9174