Ezequiel Rosas Garcia created CXF-7248:
------------------------------------------

             Summary: JAX-RS @Context injected fields cause a NPE in re-used 
providers from OSGI
                 Key: CXF-7248
                 URL: https://issues.apache.org/jira/browse/CXF-7248
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.0.12, 3.1.9, 2.7.18
            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: 
https://github.com/nhtzr/osgiee-web/blob/master/src/test/java/mx/nhtzr/osgiee/web/internal/MyFilterTest.java
PR: https://github.com/apache/cxf/pull/235



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to