Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-2195

Injection of RestClient into @Health bean fails with java.lang.IllegalStateException

    XMLWordPrintable

Details

    Description

      Injecting mp rest client using cdi producer into @Health bean fails with:
      java.lang.IllegalStateException: No RestClientBuilderResolver implementation found!

      Reproducer: https://github.com/dekstroza/sandbox/tree/couchdb/sandboxapp
      Test fails with the exception above, full stack trace: https://gist.github.com/dekstroza/c002fc9fe16698b5a5528168f6f6bc30.

      Health bean:

      @Health
      public class MyHealthCheck implements HealthCheck {
      
          @Inject
          private Logger logger;
      
          @RestClient
          @Inject
          private SomeServiceAPI someServiceAPI;
      
          @Override
          public HealthCheckResponse call() {
              logger.info("Healthcheck has been called");
              String resp = someServiceAPI.getHelloWorld();
              logger.info("Response was: {}", resp);
              return HealthCheckResponse.named("Dekstroza's Healthcheck").up().build();
          }
      }
      

      Producer:

      @ApplicationScoped
      public class RestClientProducer {
      
          @Inject
          private Logger log;
      
          @RestClient
          @Produces
          public SomeServiceAPI produceSomeServiceClient(InjectionPoint injectionPoint) {
              try {
                  return RestClientBuilder.newBuilder().baseUrl(new URL("http://localhost:8080/")).build(SomeServiceAPI.class);
              } catch (MalformedURLException e) {
                  log.error("Error creating url", e);
                  throw new RuntimeException(e);
              }
          }
      }
      

      Attachments

        Activity

          People

            mkouba@redhat.com Martin Kouba
            dekstroza Dejan Kitic (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: