Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6005

ResourceInfo cannot be injected in OSGi environment

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Duplicate
    • 2.7.12
    • 2.7.12, 3.1
    • JAX-RS
    • None
    • Unknown

    Description

      Problem: by injection of ResourceInfo in resource class or in provider in OSGi environment CXF throws following exception:

      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)
      

      Reason of the problem: there is no dedicated thread local context for ResourceInfo and CXF instantiates it using java reflection proxy in InjectionUtils:

                  return (ThreadLocalProxy<T>)Proxy.newProxyInstance(type.getClassLoader(),
                                         new Class[] {type, ThreadLocalProxy.class },
                                         new ThreadLocalInvocationHandler<T>());
      

      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.

      Attachments

        Activity

          People

            ashakirin Andrei Shakirin
            ashakirin Andrei Shakirin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: