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 4d4d5c1c71c80..fcb77dda16f83 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 @@ -101,11 +101,13 @@ 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.ResteasyViolationExceptionMapper; 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; import io.quarkus.resteasy.common.spi.ResteasyDotNames; +import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem; import io.quarkus.resteasy.reactive.spi.ExceptionMapperBuildItem; import io.quarkus.runtime.LocalesBuildTimeConfig; import io.quarkus.runtime.configuration.ConfigBuilder; @@ -331,6 +333,7 @@ void registerAdditionalBeans(HibernateValidatorRecorder hibernateValidatorRecord BuildProducer unremovableBean, BuildProducer autoScopes, BuildProducer syntheticBeanBuildItems, + BuildProducer resteasyJaxrsProvider, Capabilities capabilities) { // The bean encapsulating the Validator and ValidatorFactory additionalBeans.produce(new AdditionalBeanBuildItem(ValidatorProvider.class)); @@ -353,6 +356,8 @@ void registerAdditionalBeans(HibernateValidatorRecorder hibernateValidatorRecord .supplier(hibernateValidatorRecorder.resteasyConfigSupportSupplier( resteasyConfigBuildItem.isPresent() ? resteasyConfigBuildItem.get().isJsonDefault() : false)) .done()); + resteasyJaxrsProvider.produce(new ResteasyJaxrsProviderBuildItem(ResteasyViolationExceptionMapper.class.getName())); + } else if (capabilities.isPresent(Capability.RESTEASY_REACTIVE)) { // The CDI interceptor which will validate the methods annotated with @JaxrsEndPointValidated additionalBeans.produce(new AdditionalBeanBuildItem( diff --git a/extensions/hibernate-validator/runtime/src/main/resources/META-INF/services/jakarta.ws.rs.ext.Providers b/extensions/hibernate-validator/runtime/src/main/resources/META-INF/services/jakarta.ws.rs.ext.Providers deleted file mode 100644 index c88efb99cf024..0000000000000 --- a/extensions/hibernate-validator/runtime/src/main/resources/META-INF/services/jakarta.ws.rs.ext.Providers +++ /dev/null @@ -1 +0,0 @@ -io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyViolationExceptionMapper diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java index 0eda9df3d1217..59368bf1cfa35 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java @@ -18,6 +18,7 @@ import java.util.stream.Collectors; import jakarta.ws.rs.Priorities; +import jakarta.ws.rs.ext.Providers; import jakarta.ws.rs.ext.RuntimeDelegate; import org.jboss.jandex.AnnotationTarget; @@ -45,8 +46,11 @@ import io.quarkus.arc.deployment.BeanContainerBuildItem; import io.quarkus.arc.deployment.BuildTimeConditionBuildItem; import io.quarkus.arc.deployment.GeneratedBeanBuildItem; +import io.quarkus.deployment.Capabilities; +import io.quarkus.deployment.Capability; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; @@ -70,6 +74,19 @@ public class ResteasyReactiveCommonProcessor { private static final int LEGACY_READER_PRIORITY = Priorities.USER * 2; // readers are compared by decreased priority private static final int LEGACY_WRITER_PRIORITY = Priorities.USER / 2; // writers are compared by increased priority + private static final String PROVIDERS_SERVICE_FILE = "META-INF/services/" + Providers.class.getName(); + + @BuildStep + void searchForProviders(Capabilities capabilities, + BuildProducer producer) { + if (capabilities.isPresent(Capability.RESTEASY) || capabilities.isPresent(Capability.REST_CLIENT)) { + // in this weird case we don't want the providers to be registered automatically as this would lead to multiple bean definitions + return; + } + // TODO: should we also be looking for the specific provider files? + producer.produce(new AdditionalApplicationArchiveMarkerBuildItem(PROVIDERS_SERVICE_FILE)); + } + @BuildStep void setUpDenyAllJaxRs( CombinedIndexBuildItem index,