Class ServerExceptionMapperGenerator

java.lang.Object
org.jboss.resteasy.reactive.server.processor.generation.exceptionmappers.ServerExceptionMapperGenerator

public final class ServerExceptionMapperGenerator extends Object
  • Method Details

    • generatePerClassMapper

      public static Map<String,String> generatePerClassMapper(org.jboss.jandex.MethodInfo targetMethod, io.quarkus.gizmo.ClassOutput classOutput, Set<org.jboss.jandex.DotName> unwrappableTypes, Set<String> additionalBeanAnnotations)
      Generates an exception mapper that delegates exception handling to a method of a Resource class. For example, for a method like:
       @ServerExceptionMapper(IllegalArgumentException.class)
       public Response perClassMapper(IllegalArgumentException e, Request r) {
      
       }
       

      a generated exception mapper would look like this (only the actual called method is displayed)

       @Singleton
       @Unremovable
       public class GreetingResource$GeneratedExceptionHandlerFor$IllegalArgumentException$OfMethod$perClassMapper
               implements ResteasyReactiveExceptionMapper {
      
           public Response toResponse(IllegalArgumentException e, ServerRequestContext ctx) {
               GreetingResource instance = (GreetingResource) ((ResteasyReactiveRequestContext) ctx).getEndpointInstance();
               return instance.perClassMapper(e, ctx.getRequest());
           }
       }
       

      An example of a generated exception handler that returns Uni is:

       @Singleton
       @Unremovable
       public class GreetingResource$GeneratedExceptionHandlerFor$IllegalArgumentException$OfMethod$perClassMapper
               implements ResteasyReactiveAsyncExceptionMapper {
      
           public void asyncResponse(IllegalArgumentException e, AsyncExceptionMapperContext ctx) {
               GreetingResource instance = (GreetingResource) ((ResteasyReactiveRequestContext) ctx).getEndpointInstance();
               AsyncExceptionMappingUtil.handleUniResponse(instance.perClassMapper(e, ctx.getRequest()));
           }
       }
       
      Returns:
      a map containing the exception class name as the key and the generated exception mapper as the value
    • generateGlobalMapper

      public static Map<String,String> generateGlobalMapper(org.jboss.jandex.MethodInfo targetMethod, io.quarkus.gizmo.ClassOutput classOutput, Set<org.jboss.jandex.DotName> unwrappableTypes, Set<String> additionalBeanAnnotations, Predicate<org.jboss.jandex.MethodInfo> isOptionalMapper)
      Generates an implementation of ResteasyReactiveExceptionMapper that delegates to the method annotated with @ServerExceptionMapper.

      An example of the generated code is:

      
       @Singleton
       @Unremovable
       public class CustomExceptionMapper$GeneratedExceptionHandlerFor$IllegalArgumentException$OfMethod$handle
               implements ResteasyReactiveExceptionMapper {
           private final CustomExceptionMapper delegate;
      
           @Inject
           public CustomExceptionMapper$GeneratedExceptionHandlerFor$IllegalArgumentException$OfMethod$handle(
                   CustomExceptionMapper var1) {
               this.delegate = var1;
           }
      
           public Response toResponse(IllegalArgumentException e, ServerRequestContext ctx) {
               return delegate.handle(e, ctx.getRequest());
           }
       }
      
       

      An example of a generated exception handler that returns Uni is:

      
       @Singleton
       @Unremovable
       public class CustomExceptionMapper$GeneratedExceptionHandlerFor$IllegalArgumentException$OfMethod$handle
               implements ResteasyReactiveAsyncExceptionMapper {
           private final CustomExceptionMapper delegate;
      
           @Inject
           public CustomExceptionMapper$GeneratedExceptionHandlerFor$IllegalArgumentException$OfMethod$handle(
                   CustomExceptionMapper var1) {
               this.delegate = var1;
           }
      
           public void asyncResponse(IllegalArgumentException e, AsyncExceptionMapperContext ctx) {
               AsyncExceptionMappingUtil.handleUniResponse(delegate.handle(e, ctx.getRequest()));
           }
       }
      
       

      Returns a map containing the handled exception name as the key and the generated class name as the value