Home > Net >  Runtime error in my custom quarkus extension
Runtime error in my custom quarkus extension

Time:11-28

I am writing a quite simple quarkus extension: I want to define some specific classes about error management. For instance: I want to init a Jaxrs ExceptionMapper that captures some custom Exceptions.

Anyway, what i have tried to do is:

deployment module:

public class ErrorManagerProcessor {

  private static final String EXCEPTION_MAPPER_FEATURE = "exception-mapper";

  private static final Class<? extends ExceptionMapper<?>> EXCEPTION_MAPPER_CLASS =
    RestExceptionMapper.class;

  @BuildStep
  FeatureBuildItem createFeatureItem() {
    return new FeatureBuildItem(EXCEPTION_MAPPER_FEATURE);
  }

  @BuildStep
  ResteasyJaxrsProviderBuildItem create() {       
    return new ResteasyJaxrsProviderBuildItem(EXCEPTION_MAPPER_CLASS.getName());
  }

  @BuildStep
  void registerJaxRsProviders(final BuildProducer<ResteasyJaxrsProviderBuildItem> providers) {
    providers.produce(create());
  }
}

And in my runtime module i defined my Exception, my Mapper and a basic POJO:

public class RestException extends RuntimeException{
  public final ErrorMessage errorMessage;
  public final Status status;

  public RestException(String code, String message, Status status) {
    this.errorMessage = new ErrorMessage(code, message);
    this.status = status;
  }
}

my mapper

@Provider
public class RestExceptionMapper 
           implements ExceptionMapper<RestException> {

  @Override
  public Response toResponse(RestException e) {

    return Response
        .status(e.status)
        .entity(e.errorMessage)
        .build();
  }
}

My unit tests and my integration tests are ok, but when i run a quarkus app in dev mode with my extension loaded, I get a weird error:

java.lang.ClassNotFoundException: io.quarkus.test.common.http.TestHTTPConfigSourceProvider

Can anyone help me on this please ?

Thanks

CodePudding user response:

In case of someone would face the same issue, it was due to a bad scope definition in my deployment/pom.xml:

before:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-junit5-internal</artifactId>
</dependency>

after:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-junit5-internal</artifactId>
  <scope>test</scope>
</dependency>
  • Related