diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/AbstractLocaleResolver.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/AbstractLocaleResolver.java index 2c5674b07e85e..d5d2f70d344fb 100644 --- a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/AbstractLocaleResolver.java +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/AbstractLocaleResolver.java @@ -8,12 +8,17 @@ import org.hibernate.validator.spi.messageinterpolation.LocaleResolver; import org.hibernate.validator.spi.messageinterpolation.LocaleResolverContext; import org.jboss.logging.Logger; +import org.jboss.resteasy.reactive.common.util.CaseInsensitiveMap; abstract class AbstractLocaleResolver implements LocaleResolver { private static final Logger log = Logger.getLogger(AbstractLocaleResolver.class); private static final String ACCEPT_HEADER = "Accept-Language"; + /** + * @return case-insensitive map + * @see CaseInsensitiveMap + */ protected abstract Map> getHeaders(); @Override diff --git a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/ResteasyReactiveLocaleResolver.java b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/ResteasyReactiveLocaleResolver.java index ff3565546883c..7756a2f547626 100644 --- a/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/ResteasyReactiveLocaleResolver.java +++ b/extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/locale/ResteasyReactiveLocaleResolver.java @@ -1,12 +1,13 @@ package io.quarkus.hibernate.validator.runtime.locale; -import java.util.HashMap; import java.util.List; import java.util.Map; import jakarta.inject.Inject; import jakarta.inject.Singleton; +import org.jboss.resteasy.reactive.common.util.CaseInsensitiveMap; + import io.quarkus.arc.Arc; import io.quarkus.arc.ManagedContext; import io.quarkus.vertx.http.runtime.CurrentVertxRequest; @@ -31,7 +32,7 @@ protected Map> getHeaders() { } RoutingContext current = currentVertxRequest.getCurrent(); if (current != null) { - Map> result = new HashMap<>(); + Map> result = new CaseInsensitiveMap(); MultiMap headers = current.request().headers(); for (String name : headers.names()) { result.put(name, headers.getAll(name)); diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TextResource.java b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TextResource.java index 7813814e53031..9c5148c026cdf 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TextResource.java +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/java/io/quarkus/it/hibernate/validator/TextResource.java @@ -13,7 +13,7 @@ public class TextResource { @GET @Path("/validate/{id}") public String validate( - @Digits(integer = 5, fraction = 0, message = "numeric value out of bounds") @PathParam("id") String id) { + @Digits(integer = 5, fraction = 0) @PathParam("id") String id) { return id; } @@ -21,7 +21,7 @@ public String validate( @Path("/validate/text/{id}") @Produces(MediaType.TEXT_PLAIN) public String validateText( - @Digits(integer = 5, fraction = 0, message = "numeric value out of bounds") @PathParam("id") String id) { + @Digits(integer = 5, fraction = 0) @PathParam("id") String id) { return id; } } diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties b/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties new file mode 100644 index 0000000000000..e5cfac536ba43 --- /dev/null +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.locales=en,de +quarkus.default-locale=en \ No newline at end of file diff --git a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/TextResourceTest.java b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/TextResourceTest.java index b7fc426b18367..3638992514223 100644 --- a/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/TextResourceTest.java +++ b/integration-tests/hibernate-validator-resteasy-reactive/src/test/java/io/quarkus/it/hibernate/validator/TextResourceTest.java @@ -1,6 +1,8 @@ package io.quarkus.it.hibernate.validator; +import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.containsString; import org.junit.jupiter.api.Test; @@ -25,4 +27,22 @@ public void fetchText() { .statusCode(400) .contentType(ContentType.TEXT); } + + @Test + public void shouldGetAcceptLanguageLocaleIfKeyIsUpperCase() { + given() + .header("Accept-Language", "de") + .when().get("/text/validate/boom") + .then().log().ifValidationFails() + .body(containsString("numerischer Wert außerhalb des gültigen Bereichs")); + } + + @Test + public void shouldGetAcceptLanguageLocaleIfKeyIsLowerCase() { + given() + .header("accept-language", "de") + .when().get("/text/validate/boom") + .then().log().ifValidationFails() + .body(containsString("numerischer Wert außerhalb des gültigen Bereichs")); + } }