The recommendation would almost certainly be to use the XML Parser Service. You 
can see it in the spec at 
https://osgi.org/specification/osgi.cmpn/7.0.0/util.xml.html 
<https://osgi.org/specification/osgi.cmpn/7.0.0/util.xml.html> - note that this 
spec is pretty old, so all the examples use the low-level OSGi framework API.

Best Regards,

Tim

> On 27 Mar 2018, at 09:17, Nicolas Brasey <nicolas.bra...@gmail.com> wrote:
> 
> Hi,
> 
> I'm feeling frustrated because like everytime I'm adventuring with XML in an 
> OSGi context, I end up with classloading issues, and this time is no 
> exception :-) So I would like to know what/how you guys are doing it...
> 
> My use case is extremely simple, yet I can't figure out what I'm doing wrong. 
> I need to use an XML parser to get a Document object from an XML file. This 
> XML parsing code is embedded inside a service (DS). The weird thing is that 
> If I invoke this service with a karaf command, then it works fine. If the 
> same code is invoked through a REST endpoint (another bundle), then I get the 
> following class not found:
> 
> Caused by: java.util.ServiceConfigurationError: 
> javax.xml.parsers.DocumentBuilderFactory: Provider 
> org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
>       at java.util.ServiceLoader.fail(ServiceLoader.java:239) ~[?:?]
>       at java.util.ServiceLoader.access$300(ServiceLoader.java:185) ~[?:?]
>       at 
> java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372) 
> ~[?:?]
> 
> 
> AFAIK, Karaf is pulling the servicemix implementation of Xerces, and I 
> doubled check that the package is available in karaf:
> 
> 
> dms@root>exports | grep org.apache.xerces.jaxp
> org.apache.xerces.jaxp.datatype                                               
>                          │ 2.11.0                             │ 348 │ 
> org.apache.servicemix.bundles.xerces
> org.apache.xerces.jaxp.validation                                             
>                          │ 2.11.0                             │ 348 │ 
> org.apache.servicemix.bundles.xerces
> org.apache.xerces.jaxp                                                        
>                          │ 2.11.0                             │ 348 │ 
> org.apache.servicemix.bundles.xerces
> 
> 
> 
> So, I don't know what I'm doing wrong here.
> 
> Any clue ?
> 
> 
> Thanks,
> Nicolas
> 

Reply via email to