Skip to content

Commit

Permalink
Automatically lookup Providers based on the presence of standard Jaka…
Browse files Browse the repository at this point in the history
…rta file

Closes: #33262
  • Loading branch information
geoand committed May 11, 2023
1 parent 936737b commit c6ce5bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -331,6 +333,7 @@ void registerAdditionalBeans(HibernateValidatorRecorder hibernateValidatorRecord
BuildProducer<UnremovableBeanBuildItem> unremovableBean,
BuildProducer<AutoAddScopeBuildItem> autoScopes,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItems,
BuildProducer<ResteasyJaxrsProviderBuildItem> resteasyJaxrsProvider,
Capabilities capabilities) {
// The bean encapsulating the Validator and ValidatorFactory
additionalBeans.produce(new AdditionalBeanBuildItem(ValidatorProvider.class));
Expand All @@ -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(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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<AdditionalApplicationArchiveMarkerBuildItem> 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,
Expand Down

0 comments on commit c6ce5bb

Please sign in to comment.