-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullPointerException using @Provider in MP Rest Client #2773
Comments
Any news on this ? Ken have you understood the problem ? |
I read in the specs that JAX-RS resources can be used as CDI injection
target, and it works great when I use it as server resources.
It doesn't work when the same @Provider is used from the MP Rest Client.
Il giorno ven 28 giu 2019 alle ore 16:25 Ken Finnigan <
[email protected]> ha scritto:
… Without smallrye-rest-client in the project @Inject works?
I'm not sure if @Inject is intended to work inside a JAX-RS @Provider.
Not sure if @mkouba <https://github.com/mkouba> or @asoldano
<https://github.com/asoldano> know
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2773?email_source=notifications&email_token=AAPXERQZLKGHV35CSZ67BITP4YNONA5CNFSM4HWSLAT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY2HDLI#issuecomment-506753453>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPXERV5NH352KKI7TTF3FTP4YNONANCNFSM4HWSLATQ>
.
--
****************************************
http://www.lucamasini.net
http://twitter.com/lmasini
http://www.linkedin.com/pub/luca-masini/7/10/2b9
****************************************
|
That’s correct that you can inject CDI beans into JAX-RS Resource classes.
However, I don’t believe that JAX-RS Providers support injection with CDI.
…Sent from my iPhone
On Jun 28, 2019, at 15:21, masini ***@***.***> wrote:
I read in the specs that JAX-RS resources can be used as CDI injection
target, and it works great when I use it as server resources.
It doesn't work when the same @Provider is used from the MP Rest Client.
Il giorno ven 28 giu 2019 alle ore 16:25 Ken Finnigan <
***@***.***> ha scritto:
> Without smallrye-rest-client in the project @Inject works?
>
> I'm not sure if @Inject is intended to work inside a JAX-RS @Provider.
> Not sure if @mkouba <https://github.com/mkouba> or @asoldano
> <https://github.com/asoldano> know
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#2773?email_source=notifications&email_token=AAPXERQZLKGHV35CSZ67BITP4YNONA5CNFSM4HWSLAT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY2HDLI#issuecomment-506753453>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAPXERV5NH352KKI7TTF3FTP4YNONANCNFSM4HWSLATQ>
> .
>
--
****************************************
http://www.lucamasini.net
http://twitter.com/lmasini
http://www.linkedin.com/pub/luca-masini/7/10/2b9
****************************************
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
The specs says yes from what I can read, I copy paste here for your
convenience.
" JAX-RS: Java API for RESTful Web Services
10.2.3 Context and Dependency Injection (CDI)
In a product that supports CDI, implementations *MUST* support the use of
CDI-style Beans as root resource classes, *providers* and Application
subclasses.
Providers and Application subclasses MUST be singletons or use application
scope."
Il giorno ven 28 giu 2019 alle ore 21:44 Ken Finnigan <
[email protected]> ha scritto:
… That’s correct that you can inject CDI beans into JAX-RS Resource classes.
However, I don’t believe that JAX-RS Providers support injection with CDI.
Sent from my iPhone
> On Jun 28, 2019, at 15:21, masini ***@***.***> wrote:
>
> I read in the specs that JAX-RS resources can be used as CDI injection
> target, and it works great when I use it as server resources.
>
> It doesn't work when the same @Provider is used from the MP Rest Client.
>
>
> Il giorno ven 28 giu 2019 alle ore 16:25 Ken Finnigan <
> ***@***.***> ha scritto:
>
> > Without smallrye-rest-client in the project @Inject works?
> >
> > I'm not sure if @Inject is intended to work inside a JAX-RS @Provider.
> > Not sure if @mkouba <https://github.com/mkouba> or @asoldano
> > <https://github.com/asoldano> know
> >
> > —
> > You are receiving this because you authored the thread.
> > Reply to this email directly, view it on GitHub
> > <
#2773?email_source=notifications&email_token=AAPXERQZLKGHV35CSZ67BITP4YNONA5CNFSM4HWSLAT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY2HDLI#issuecomment-506753453
>,
> > or mute the thread
> > <
https://github.com/notifications/unsubscribe-auth/AAPXERV5NH352KKI7TTF3FTP4YNONANCNFSM4HWSLATQ
>
> > .
> >
>
>
> --
> ****************************************
> http://www.lucamasini.net
> http://twitter.com/lmasini
> http://www.linkedin.com/pub/luca-masini/7/10/2b9
> ****************************************
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2773?email_source=notifications&email_token=AAPXERSPOLFWGZOU42FR3VTP4ZS2JA5CNFSM4HWSLAT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY276LQ#issuecomment-506855214>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPXERWTOBQ6N7XN6MWS4XTP4ZS2JANCNFSM4HWSLATQ>
.
--
****************************************
http://www.lucamasini.net
http://twitter.com/lmasini
http://www.linkedin.com/pub/luca-masini/7/10/2b9
****************************************
|
So I'm not really sure as I am no JAX-RS expert. However, it seems that even JAX-RS built-in injection using the On the other hand, it could be a nice feature. @gsmet @geoand @michalszynkiewicz WDYT? |
@mkouba I am in the same exact situation you are, not a JAX-RS expert but the feature sounds reasonable |
Hey guys, I, on the other hand, don't know anything about quarkus, and, honestly, I don't have a lot of experience with MicroProfile Client. One thing that comes to mind is this: Shouldn't CountriesService have a
annotation? I tried it, though, and it doesn't help. I'll keep looking. -Ron |
@asoldano has reminded me of the existence of this issue. As the Innkeeper of Bree said, "One thing drives out another".
-Ron |
Consider that we have an asymmetric behaviour.
An example:
1) Create a Provider used Server side that use CDI injection, this works
2) The same Provider is used client side, but here the injection doesn't
work
This is confusing and constrained me to write code that understand if is
running client-side or server-side.
Il giorno mar 30 lug 2019 alle ore 20:56 Ron Sigal <[email protected]>
ha scritto:
… @asoldano <https://github.com/asoldano> has reminded me of the existence
of this issue. As the Innkeeper of Bree said, "One thing drives out
another".
1.
Currently, the expected injection does not work in RESTEasy. The fact
is that there is no discussion in the JAX-RS spec of how to treat a Client
created on a server. Given the importance of the issue, I think it's
something that should be addressed, eventually.
2.
In the meantime, making the injection work is a feature we *could* add
to RESTEasy. We've been discussing how to do it. For example, we could
support CDI injection for clients, wherever they live.
-Ron
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2773?email_source=notifications&email_token=AAPXERQ35BFBNGJRXAM4JCTQCCFETA5CNFSM4HWSLAT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3E6RMY#issuecomment-516548787>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPXERT3ISQHS5SK3P5BCA3QCCFETANCNFSM4HWSLATQ>
.
--
****************************************
http://www.lucamasini.net
http://twitter.com/lmasini
http://www.linkedin.com/pub/luca-masini/7/10/2b9
****************************************
|
@masini, I'll take that as a vote for making injection work, one way or another. |
I've been looking into this issue again, and I have some information to add. I've turned the example at https://github.com/masini/quarkus-rest-client-npe into a WAR, deployed it to Wildfly, and it works as expected, i.e., there is no NPE. This suggests to me that there might be some issue with CDI in Quarkus. I'm sadly ignorant about Quarkus, but I got the following comment from Bill Burke: "I'd make sure that the ContextResolver is being allocated by Arc (quarkus cdi implementation)." Can someone from the Quarkus group comment? |
I can take a quick look tomorrow |
I looked at this again briefly without reading the discussion and it struck as odd that |
@geoand, just to be sure, by "we" you mean Quarkus? |
@ronsigal yup :) |
Cool. ;-) |
Well, I don't think this is a CDI/ArC issue. The beans for I've debugged the reproducer and the provider instance is created here: https://github.com/resteasy/Resteasy/blob/master/providers/json-binding/src/main/java/org/jboss/resteasy/plugins/providers/jsonb/AbstractJsonBindingProvider.java#L27 which delegates to And so I believe that if we use the |
I like the idea and it sound perfectly reasonable although I admit I don't know much about the client |
@mkouba, I think we're seeing different things. I've added a no-arg constructor to JsonbContextResolver:
and I see the JsonbContextResolver created in three steps. In particular, there is a QuarkusInjectorFactory in step 3 below:
org.acme.restclient.JsonbContextResolver@142269f2
org.acme.restclient.JsonbContextResolver_ClientProxy@d8305c2
|
@ronsigal Ok, I need to double check. Anyway, pls upgrade the reproducer, ie. quarkus from 0.16.1 to 0.22.0 and |
@ronsigal Ok, so I've tried to add a no-arg constructor to the 1. Instance created for RestClient -
|
OK, so I got this working with a quick and dirty fix. Basically all we need to do is use the I say that the fix is quick and dirty because I just copied stuff from |
This is done in order to have providers as beans - same as is the case for resteasy server. Fixes quarkusio#2773
This is done in order to have providers as beans - same as is the case for resteasy server. Fixes quarkusio#2773
This is done in order to have providers as beans - same as is the case for resteasy server. Fixes quarkusio#2773
Ensure that resteasy rest-client uses QuarkusInjectorFactory as well
Describe the bug
@Inject doesn't work in @Provider when the Provider is used by MP Rest Client
Expected behavior
The Bean injected
Actual behavior
The Bean field is null
To Reproduce
Steps to reproduce the behavior:
The text was updated successfully, but these errors were encountered: