0 Replies Latest reply on Mar 15, 2011 12:43 PM by futuredan

    Confused about OSGi classloading in ServiceMix 4.3

    futuredan

      I am trying to solve two different problems and it seems that classloading is behaving differently in each case.

      In each case, I am using a 3rd party jar that I have wrapped as an OSGi bundle.

       

      In one case, the 3rd party code makes a call to javax.xml.transform.TransformerFactory.newInstance.

      I need for this call to use org.apache.xalan.processor.TransformerFactoryImpl as the transformer.  I also need it to use a specific version of Xalan.

      I solved the first issue by setting the java property javax.xml.transform.TransformerFactory to org.apache.xalan.processor.TransformerFactoryImpl.

      For the second issue, I would have thought that specifying the correct Xalan version in the Import-Package section of the bundle I created for the 3rd party jar would have been enough.

      However, it seems that I need to specify that Import-Package in the bundle that contains the context that contains the route that eventually leads to the code being called.

       

      I would have assumed that it would always use the classloader from the OSGi bundle that I created for the 3rd party jar.

      Why doesn't that seem to be the case?

       

      In the other case, the (different) 3rd party jar is creating a singleton.  I'd prefer that each camel context get its own copy of the singleton.  However, it doesn't appear that in this case it is using the classloader for the context because only one instance of the singleton is created.

      Why is this behavior different from what appears to be happening in the above case?

       

      I would appreciate any insight into this issue.

       

      Edited by: futuredan on Mar 15, 2011 12:39 PM