cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <>
Subject [jira] [Commented] (CXF-7248) JAX-RS @Context injected fields cause a NPE in re-used providers from OSGI
Date Mon, 13 Feb 2017 11:57:41 GMT


Sergey Beryozkin commented on CXF-7248:

Thanks for the patch, I've applied it (note CXF 2.7.x line is no longer supported).
I think the idea of reusing the providers is great.
The tricky part is to figure out how to handle the context if the providers are used across
multiple resources with different CXF bus instances, I vaguely recall that the first time
an issue like this occurred in a Camel route. We have a test in CXF but where a single Jackson
provider is linked to different resources with unique CXF buses, but I guess the reason I
did not see this bug was that Jackson is not proxified and the code checking the Field works


> JAX-RS @Context injected fields cause a NPE in re-used providers from OSGI
> --------------------------------------------------------------------------
>                 Key: CXF-7248
>                 URL:
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.7.18, 3.1.9, 3.0.12
>            Reporter: Ezequiel Rosas Garcia
> Hi. 
> The explanation is kind of long, but the code issue I found is simple, please look at
the linked PR. 
> Most of the text will be about what I have attempted, in hopes of getting any comment
on what I'm trying to archieve:
> I have a bean implementing ContainerRequestFilter that I'm obtaining through OSGI, and
this bean has a {{@Context}} injected field. All of the bundles in my application are setting
this bean as a Provider via JAXRS.
> At first, the {{@Context}} annotation was used directly on the field of the implementing
class. This caused the injection to fail on all bundles trying to use it, because it seems
the imported object via osgi was a Proxy rather than the actual original bean that was exported.
CXF attempted to look for any field to inject, but the Proxy never exposed anything of the
underlying object.
> The next attempt was putting the {{@Context}} annotation on the setter method in a new
interface the filter is now implementing.
> Now, the first bundle works properly, but then fails as described in the title of this
issue: After the second bundle is deployed, trying to call any method of the injected field
when handling the first endpoint (from the first bundle) will throw an NPE (the field itself
isn't null tho)
> Digging through the code, I can see that a ThreadLocal proxy in combination with a map
are being used for the injection. 
> And that each endpoint can re use the same ThreadLocal proxy as long as CXF can retrieve
it from the provider bean.
> Finally, I added a getter method for the injected field, but the problem persisted. The
linked PR fixes InjectionUtils#getGetterFromSetter so this problem goes away.
> I wanted to also ask. Is this a good approach for reusing the filter through OSGI?
> Test:
> PR:

This message was sent by Atlassian JIRA

View raw message