Quarkus: Microprofile rest client - Can't inject config/beans to providers

Created on 25 Nov 2019  路  22Comments  路  Source: quarkusio/quarkus

Describe the bug
Any provider added to rest client via @Provider annotation is unable to inject config bean or any other application scoped bean.

@RegisterRestClient
@RegisterProvider(RequestFilter.class)
public interface EchoService {....}

And example the provider impl:

public class RequestFilter implements ClientRequestFilter {
  @Inject
  AppConfig config;  //is always null

  @Inject
  SomeBean bean; //is always null

  @Override
  public void filter(ClientRequestContext requestContext) throws IOException {...}

Expected behavior
Config or application scope bean injected and not null

Actual behavior
Any bean injected via @Inject is alway null (no errors in logs during argumentation nor during runtime.

To Reproduce
Steps to reproduce the behavior:

  1. Use reproducer: https://github.com/marcinczeczko/quarkus-rest-providers-reproducer
  2. mvn compile quarkus:dev
  3. curl http://localhost:8080/echo
  4. Check the logs - the injected config & app bean shows null reference

Configuration

  • See reproducer

Screenshots
N/A

Environment (please complete the following information):

  • Output of uname -a or ver: 18.7.0 Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64 x86_64
  • Output of java -version:
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
  • GraalVM version (if different from Java): Didn't check on graalvm
  • Quarkus version or git rev: 1.0.0.Final

Additional context

I found out there is a closed issue for similar problem, but looks like the fix doesn't work, see: https://github.com/quarkusio/quarkus/issues/2773

arerest-client kinbug

All 22 comments

Ok, so an easy workaround is to annotate the provider class with @Provider but this would probably defeat the purpose of the @RegisterProvider annotation because the provider would be discovered and automatically registered for all rest client interfaces and even server-side resources.

Looking at the RestClientBuilderImpl it seems that the creation of providers registered through @RegisterProvider is hard-coded and is using Class.newInstance(). See https://github.com/resteasy/Resteasy/blob/master/resteasy-client-microprofile/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java#L205-L207 and https://github.com/resteasy/Resteasy/blob/master/resteasy-client-microprofile/src/main/java/org/jboss/resteasy/microprofile/client/RestClientBuilderImpl.java#L452-L458.

I believe that this should be changed so that the provided ResteasyProviderFactory is used instead. @geoand @kenfinnigan WDYT?

I believe that this should be changed so that the provided ResteasyProviderFactory is used instead. @geoand @kenfinnigan WDYT?

+1 for me

@geoand would you care to send a PR to resteasy? ;-)

@mkouba sure, I'll most likely get to it this week

@mkouba @geoand By the way, I updated my reproducer to verify @RegisterClientHeaders to add ClientHeadersFactory to the client - and in fact it has the same issue with no beans injected.

@geoand it looks like something we would want for 1.1.0 so please ask for a RESTEasy release including that one before December 6th.

Thanks!

@gsmet Sure!

Once I finish my current task, I'll pick up this one.

I opened a PR in RESTEasy that forms part of the solution.
The other part will be to register the classes used in @RegisterProvider as beans.

@geoand Thanks!

@mkouba YW!

@asoldano when do you expect RESTEasy 4.5.0.Final will be released?
@gsmet if it's out soon enough, do you think we can have it for Quarkus 1.1.0.Final or are we too close to release?

I'm not yet sure of when we will be able to release given all the problems we have.

But I'm not sure either if RESTEasy 4.5.0.Final will be an easy upgrade.

So I would say: release it, prepare a PR and we'll see how it goes :).

@geoand , @gsmet , the current plan is to release another micro from resteasy master, so 4.4.2.Final, by the end of this week.

Ok, that one will be for 1.2 then.

Or if we need a 1.1.1 for some other reason, we can get this fix in as well

4.4.2.Final is released

@asoldano Thanks!

Do you plan to create a Quarkus PR to bump the RESTEasy version?

PR bumping the version is here: https://github.com/quarkusio/quarkus/pull/6283

RESTEasy update PR was merged 10 days ago, is this issue fixed now ?

@rsvoboda yes, I'll close it.

From my perspective this issue is still present. Even if I upgrade the project from here to 1.2.1.Final all injected beans are still "null"

@sassko can you open a new issue with your reproducer linked? Thanks!

Was this page helpful?
0 / 5 - 0 ratings