diff --git a/extensions/hibernate-orm/deployment/pom.xml b/extensions/hibernate-orm/deployment/pom.xml index f1cd0a90c9730..a074ca924641a 100644 --- a/extensions/hibernate-orm/deployment/pom.xml +++ b/extensions/hibernate-orm/deployment/pom.xml @@ -41,6 +41,10 @@ io.quarkus quarkus-panache-hibernate-common-deployment + + io.quarkus + quarkus-resteasy-reactive-server-spi-deployment + io.quarkus quarkus-junit5-internal diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ResteasyReactiveServerIntegrationProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ResteasyReactiveServerIntegrationProcessor.java new file mode 100644 index 0000000000000..b91aed743bfef --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ResteasyReactiveServerIntegrationProcessor.java @@ -0,0 +1,14 @@ +package io.quarkus.hibernate.orm.deployment; + +import javax.persistence.PersistenceException; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.resteasy.reactive.server.spi.UnwrappedExceptionBuildItem; + +public class ResteasyReactiveServerIntegrationProcessor { + + @BuildStep + public UnwrappedExceptionBuildItem unwrappedExceptions() { + return new UnwrappedExceptionBuildItem(PersistenceException.class); + } +} diff --git a/extensions/hibernate-reactive/deployment/pom.xml b/extensions/hibernate-reactive/deployment/pom.xml index 283a0b43c7c4a..573d77e161f7a 100644 --- a/extensions/hibernate-reactive/deployment/pom.xml +++ b/extensions/hibernate-reactive/deployment/pom.xml @@ -61,6 +61,10 @@ io.quarkus quarkus-mutiny-deployment + + io.quarkus + quarkus-resteasy-reactive-server-spi-deployment + io.quarkus quarkus-junit5-internal diff --git a/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/ResteasyReactiveServerIntegrationProcessor.java b/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/ResteasyReactiveServerIntegrationProcessor.java new file mode 100644 index 0000000000000..3ad61c5a1aed7 --- /dev/null +++ b/extensions/hibernate-reactive/deployment/src/main/java/io/quarkus/hibernate/reactive/deployment/ResteasyReactiveServerIntegrationProcessor.java @@ -0,0 +1,14 @@ +package io.quarkus.hibernate.reactive.deployment; + +import javax.persistence.PersistenceException; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.resteasy.reactive.server.spi.UnwrappedExceptionBuildItem; + +public class ResteasyReactiveServerIntegrationProcessor { + + @BuildStep + public UnwrappedExceptionBuildItem unwrappedExceptions() { + return new UnwrappedExceptionBuildItem(PersistenceException.class); + } +} diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveScanningProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveScanningProcessor.java index ef21c0b76abf3..c835adeffa34d 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveScanningProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveScanningProcessor.java @@ -13,6 +13,7 @@ import java.util.Set; import java.util.function.Consumer; +import javax.transaction.RollbackException; import javax.ws.rs.Priorities; import org.jboss.jandex.AnnotationInstance; @@ -58,6 +59,7 @@ import io.quarkus.resteasy.reactive.common.deployment.ResourceInterceptorsContributorBuildItem; import io.quarkus.resteasy.reactive.common.deployment.ResourceScanningResultBuildItem; import io.quarkus.resteasy.reactive.server.spi.MethodScannerBuildItem; +import io.quarkus.resteasy.reactive.server.spi.UnwrappedExceptionBuildItem; import io.quarkus.resteasy.reactive.spi.ContainerRequestFilterBuildItem; import io.quarkus.resteasy.reactive.spi.ContainerResponseFilterBuildItem; import io.quarkus.resteasy.reactive.spi.ContextResolverBuildItem; @@ -97,20 +99,29 @@ public void accept(ResourceInterceptors interceptors) { }); } + @BuildStep + public List defaultUnwrappedException() { + return List.of(new UnwrappedExceptionBuildItem(ArcUndeclaredThrowableException.class), + new UnwrappedExceptionBuildItem(RollbackException.class)); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) @BuildStep public ExceptionMappersBuildItem scanForExceptionMappers(CombinedIndexBuildItem combinedIndexBuildItem, ApplicationResultBuildItem applicationResultBuildItem, BuildProducer additionalBeanBuildItemBuildProducer, BuildProducer reflectiveClassBuildItemBuildProducer, - List mappers, Capabilities capabilities) { + List mappers, List unwrappedExceptions, + Capabilities capabilities) { AdditionalBeanBuildItem.Builder beanBuilder = AdditionalBeanBuildItem.builder().setUnremovable(); ExceptionMapping exceptions = ResteasyReactiveExceptionMappingScanner .scanForExceptionMappers(combinedIndexBuildItem.getComputingIndex(), applicationResultBuildItem.getResult()); exceptions.addBlockingProblem(BlockingOperationNotAllowedException.class); exceptions.addBlockingProblem(BlockingNotAllowedException.class); - exceptions.addUnwrappedException(ArcUndeclaredThrowableException.class); + for (UnwrappedExceptionBuildItem bi : unwrappedExceptions) { + exceptions.addUnwrappedException(bi.getThrowableClass()); + } if (capabilities.isPresent(Capability.HIBERNATE_REACTIVE)) { exceptions.addNonBlockingProblem( new ExceptionMapping.ExceptionTypeAndMessageContainsPredicate(IllegalStateException.class, "HR000068")); diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/spi-deployment/src/main/java/io/quarkus/resteasy/reactive/server/spi/UnwrappedExceptionBuildItem.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/spi-deployment/src/main/java/io/quarkus/resteasy/reactive/server/spi/UnwrappedExceptionBuildItem.java new file mode 100644 index 0000000000000..5cdee8cf359a4 --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/spi-deployment/src/main/java/io/quarkus/resteasy/reactive/server/spi/UnwrappedExceptionBuildItem.java @@ -0,0 +1,20 @@ +package io.quarkus.resteasy.reactive.server.spi; + +import io.quarkus.builder.item.MultiBuildItem; + +/** + * When an Exception of this type is thrown and no {@code javax.ws.rs.ext.ExceptionMapper} exists, + * then RESTEasy Reactive will attempt to locate an {@code ExceptionMapper} for the cause of the Exception. + */ +public final class UnwrappedExceptionBuildItem extends MultiBuildItem { + + private final Class throwableClass; + + public UnwrappedExceptionBuildItem(Class throwableClass) { + this.throwableClass = throwableClass; + } + + public Class getThrowableClass() { + return throwableClass; + } +}