Skip to content

Commit

Permalink
Merge pull request #20509 from geoand/rr-unwrapped2
Browse files Browse the repository at this point in the history
Make it easier for RESTEasy Reactive users to handle Hibernate related exceptions
  • Loading branch information
Sanne authored Oct 5, 2021
2 parents 12f7e3e + 25ce59e commit ece3e3f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions extensions/hibernate-orm/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-hibernate-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-server-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions extensions/hibernate-reactive/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mutiny-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-server-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -97,20 +99,29 @@ public void accept(ResourceInterceptors interceptors) {
});
}

@BuildStep
public List<UnwrappedExceptionBuildItem> defaultUnwrappedException() {
return List.of(new UnwrappedExceptionBuildItem(ArcUndeclaredThrowableException.class),
new UnwrappedExceptionBuildItem(RollbackException.class));
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@BuildStep
public ExceptionMappersBuildItem scanForExceptionMappers(CombinedIndexBuildItem combinedIndexBuildItem,
ApplicationResultBuildItem applicationResultBuildItem,
BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildProducer,
BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer,
List<ExceptionMapperBuildItem> mappers, Capabilities capabilities) {
List<ExceptionMapperBuildItem> mappers, List<UnwrappedExceptionBuildItem> 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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends Throwable> throwableClass;

public UnwrappedExceptionBuildItem(Class<? extends Throwable> throwableClass) {
this.throwableClass = throwableClass;
}

public Class<? extends Throwable> getThrowableClass() {
return throwableClass;
}
}

0 comments on commit ece3e3f

Please sign in to comment.