Thanks Harald-

Setting  felix.bootdelegation.implicit=**false did not work in this case.
I'm sure the forked or pax runner test container would probably work, but
I'd prefer to avoid remote debugging as I'm setting up for many developers
to use, and the preferred method is IDE-based unit test running. To that
end, changing the classpath to exclude the jar is also not possible in
IntelliJ IDEA.

However, I did find a workaround... the problem lies in the CXF
ClassLoaderUtils--they look for classes
from Thread.currentThread().getContextClassLoader(), so when running the
unit test, the classloader is the current JUnit thread, not the bundle
classloader. Therefore, it is getting SpringBusFactory from the JUnit
classloader, and BusFactory from the bundle classloader for
cxf-bundle-minimal. I found that CXF provides a convenience method to set
the thread classloader to something different. So, in my unit test class, I
am able to do the following:


ClassLoaderUtils.setThreadContextClassloader(testedClass.getClass().getClassLoader());

Where "testedClass" is the injected class I am testing. This sets the
classloader to the bundle that class is in and it properly finds the
SpringBusFactory through its OSGI dependencies. So, with this I can avoid
the pain of remote debugging.

Thanks again,
Jeff


On Fri, Feb 10, 2012 at 4:09 PM, Harald Wellmann <
hwellmann...@googlemail.com> wrote:

> With the Native Test Container, classes may be loaded both by the
> application classloader and a bundle classloader, which can cause problems.
>
> With Felix, setting the framework property felix.bootdelegation.implicit=*
> *false may help in such cases.
>
> Or even simpler, check if the runtime dependency on SpringBusFactory is
> really required. If not, exclude the JAR from the classpath and only
> provision it as OSGi bundle in your Pax Exam configuration.
>
> Otherwise, you can try using the Pax Runner Test Container or the Forked
> Test Container (new in Pax Exam 2.4.0.RC1), both of which run your tests in
> a separate VM with minimum classpath "pollution". The price for better
> classloader isolation is remote debugging.
>
> Hope that helps,
> Harald
>
>
> Am 10.02.2012 22:36, schrieb Jeff Melby:
>
>  I am developing a web service client using CXF in an OSGI bundle. The
>> service works fine when I run it in Felix. However, when I am running
>> using Pax Exam in unit testing, with Felix as the specified framework, I
>> am getting the following error when initializing the web service client.
>> It is attempting to cast SpringBusFactory as BusFactory (which
>> SpringBusFactory extends). I have confirmed that these classes both only
>> exist in the cxf-bundle-minimal 2.5.2. Still, it seems that these two
>> must have somehow ended up on separate classloaders.
>>
>> Does anyone have any thoughts on how to resolve this?
>>
>> Thanks,
>> Jeff
>>
>>
> ______________________________**_________________
> general mailing list
> general@lists.ops4j.org
> http://lists.ops4j.org/**mailman/listinfo/general<http://lists.ops4j.org/mailman/listinfo/general>
>
_______________________________________________
general mailing list
general@lists.ops4j.org
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to