Clauds Clauds - 2 months ago 9
Java Question

OpenSAML3 resource not found 'default-config.xml' in OSGi container

I'm trying to upgrade to OpenSAML 3 in an OSGi bundle running on Apache Karaf (4.0.5) using opensaml servicemix bundle (


A test that parses the SAML is working so I think I'm on the right track. However, if I install the bundle on Karaf I get a "resource not found" error when it's trying to load

2016-06-21 16:29:10,477 | INFO | ool-120-thread-1 | InitializationService | 388 - org.apache.servicemix.bundles.opensaml - | Initializing OpenSAML using the Java Services API
2016-06-21 16:29:10,478 | DEBUG | ool-120-thread-1 | InitializationService | 388 - org.apache.servicemix.bundles.opensaml - | Initializing module initializer implementation: org.opensaml.core.xml.config.XMLObjectProviderInitializer
2016-06-21 16:29:10,487 | DEBUG | ool-120-thread-1 | XMLConfigurator | 388 - org.apache.servicemix.bundles.opensaml - | XMLObjectProviderRegistry did not exist in ConfigurationService, will be created
2016-06-21 16:29:10,488 | DEBUG | ool-120-thread-1 | ractXMLObjectProviderInitializer | 388 - org.apache.servicemix.bundles.opensaml - | Loading XMLObject provider configuration from resource 'default-config.xml'
2016-06-21 16:29:10,489 | ERROR | ool-120-thread-1 | ractXMLObjectProviderInitializer | 388 - org.apache.servicemix.bundles.opensaml - | Problem loading configuration resource
org.opensaml.core.xml.config.XMLConfigurationException: Resource not found
at org.opensaml.core.xml.config.AbstractXMLObjectProviderInitializer.init([388:org.apache.servicemix.bundles.opensaml:]
at org.opensaml.core.xml.config.XMLObjectProviderInitializer.init([388:org.apache.servicemix.bundles.opensaml:]
at org.opensaml.core.config.InitializationService.initialize([388:org.apache.servicemix.bundles.opensaml:]

is loading the resource as follows (


is located in the root of the (opensaml) jar which makes me wonder if that's the reason it cannot be found.

I'm using the
in my project and on top of the dependency and various uses of opensaml classes I provided explicit imports (
) for the following packages:


Is there anything I am missing in my bundle's manifest or elsewhere to make this work? I presume the opensaml bundle released by servicemix itself should be working as is...


I found a solution to the "resource not found" issue but it's a hack more than anything...

After stumbling across the SO post Better handling of Thread Context ClassLoader in OSGi I adapted my code to set the classloader of the InitializationService before calling it, the XML in question is now found during initialization.

    // adapt TCCL
    Thread thread = Thread.currentThread();
    ClassLoader loader = thread.getContextClassLoader();
    try {
    } finally {
        // reset TCCL

However, I've noticed that my SPI config org.opensaml.core.config.Initializer does not get loaded and I have not figured out a proper fix for that yet. My current workaround is explicitly calling the init methods of initializers I need... (I'm updating OpenSAML in two projects, in one XMLObjectProviderInitializer seems to be enough, the other unfortunately is not yet working.)