You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Sergey Beryozkin (JIRA)" <ji...@apache.org> on 2014/09/16 11:33:34 UTC

[jira] [Commented] (CXF-6005) ResourceInfo cannot be injected in OSGi environment

    [ https://issues.apache.org/jira/browse/CXF-6005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14135193#comment-14135193 ] 

Sergey Beryozkin commented on CXF-6005:
---------------------------------------

Hi Andrey

I think I got it fixed, using a ProxyClassLoader, let me check...

> ResourceInfo cannot be injected in OSGi environment
> ---------------------------------------------------
>
>                 Key: CXF-6005
>                 URL: https://issues.apache.org/jira/browse/CXF-6005
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.7.12
>            Reporter: Andrei Shakirin
>            Assignee: Andrei Shakirin
>            Priority: Critical
>
> Problem: by injection of ResourceInfo in resource class or in provider in OSGi environment CXF throws following exception:
> {code}
> Caused by: java.lang.IllegalArgumentException: interface org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy is not visible from class loader
> 	at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:487)[:1.7.0_40]
> 	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:722)[:1.7.0_40]
> 	at org.apache.cxf.jaxrs.utils.InjectionUtils.createThreadLocalProxy(InjectionUtils.java:962)
> {code}
> Reason of the problem: there is no dedicated thread local context for ResourceInfo and CXF instantiates it using java reflection proxy in InjectionUtils:
> {code}
>             return (ThreadLocalProxy<T>)Proxy.newProxyInstance(type.getClassLoader(),
>                                    new Class[] {type, ThreadLocalProxy.class },
>                                    new ThreadLocalInvocationHandler<T>());
> {code}
> The problem is that classloader in first argument is taken from type class, but proxy have to implement two interfaces: type and ThreadLocalProxy (second argument). It works fine in standalone environment, but in OSGi classloader of ResourceInfo bundle doesn't know nothing about ThreadLocalProxy interface in CXF JAX-RS bundle. Of course, the ThreadLocalProxy cannot be found.
> Solution: possible solution is use the classloader of current class (InjectionUtils) instead of type class. As far as InjectionUtils classloader knows type class as well it should work in standalone as well as in OSGi environments.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)