hi, JB.

thank you for looking at this. The attached zip contains both the bundle and 
its feature file. the bundle should be placed in the /bundles dir, and you know 
what to do with the feature file =)
here are some points regarding the bundle:
1) the bundle executes automatically during Karaf startup to make it easier for 
you.
2) The bundle contains both the schema and the xml, so you dont have to really 
do anything to the bundle itself in order for it to just run
3) The bundle contains props.properties where you can specify external 
locations to both schema and xml file if you choose to do so for any reason. 
The provided files will be ignored in such case.
4) I have also provided the source .java alongside the binary just in case.

again, really appreciate you taking the time to look at it. thanks!!!

Brock Samson

________________________________
From: Jean-Baptiste Onofre <j...@nanthrax.net>
Sent: Tuesday, February 23, 2021 11:56 AM
To: user@karaf.apache.org <user@karaf.apache.org>
Subject: Re: Karaf 4.2.10 - NullPointerException during xml parsing

Hi Brock,

Maybe you have xerces installed as bundle in your distribution ?

It sounds like a version mismatch.

Can you share the bundles installed ?

Thanks,
Regards
JB

Le 23 févr. 2021 à 16:55, brock samson 
<brock.sams...@hotmail.com<mailto:brock.sams...@hotmail.com>> a écrit :

Hello,

I am using Karaf 4.2.10 and attempting to perform a rather simple xml parsing:

Caused by: java.lang.NullPointerException
                at org.apache.xerces.util.ErrorHandlerProxy.error(Unknown 
Source) ~[!/:?]
                at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:137)
 ~[?:1.8.0_102]
                at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
 ~[?:1.8.0_102]
                at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
 ~[?:1.8.0_102]
                at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
 ~[?:1.8.0_102]
                at 
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1900)
 ~[?:1.8.0_102]
                at 
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:740)
 ~[?:1.8.0_102]
                at 
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:570)
 ~[?:1.8.0_102]
                at 
org.apache.xerces.jaxp.JAXPValidatorComponent$XNI2SAX.startElement(Unknown 
Source) ~[!/:?]
                at 
org.apache.xerces.jaxp.JAXPValidatorComponent.startElement(Unknown Source) 
~[!/:?]
                at 
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown 
Source) ~[!/:?]
                at 
org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown
 Source) ~[!/:?]
                at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
 Source) ~[!/:?]
                at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source) ~[!/:?]
                at org.apache.xerces.parsers.XML11Configuration.parse(Unknown 
Source) ~[!/:?]
                at org.apache.xerces.parsers.XML11Configuration.parse(Unknown 
Source) ~[!/:?]
                at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
~[!/:?]
                at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) 
~[!/:?]
                at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown 
Source) ~[!/:?]
                at 
javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) ~[?:1.8.0_102]

After snooping around, I noticed a 
/container/lib/endorsed/org.apache.karaf.specs.java.xml-4.2.10.jar lib 
containing parser-related libs. My code executed successfully once I ran Karaf 
without this particular file, though I don’t feel right just pulling it out of 
Karaf blindly, as its absence creates a distinct possibility of unforeseen 
issues down the road.

Here are the only imports my bundle references in its manifest:
Import-Package: 
javax.xml.transform,javax.xml.transform.stream,org.xml.sax,javax.xml.parsers,javax.xml.validation
There are no entries under Bundle-Classpath

Lastly, here is the java code that performs the xml parsing:

            DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
            SchemaFactory sf = 
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new StreamSource(new 
FileInputStream("<LOCATION-OF-THE-SCHEMA-FILE>")));
            factory.setNamespaceAware(true);
            factory.setSchema(schema);
            factory.setExpandEntityReferences(false);
            factory.setXIncludeAware(false);
            
factory.setFeature("http://xml.org/sax/features/external-parameter-entities",false);
            
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
            
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl";, 
true);
            
factory.setFeature("http://xml.org/sax/features/external-general-entities",false);
            DocumentBuilder builder = factory.newDocumentBuilder();
            builder.setErrorHandler(null);
            byte[] fileContent = 
Files.readAllBytes(Paths.get("<LOCATION-OF-THE-XML-FILE-TO-BE-PARSED>"));
            InputStream inStream = new ByteArrayInputStream(fileContent);
Document doc = builder.parse(inStream);

Please advise me as to what I am doing wrong, as well as a possible solution. 
Thank you for your time!

Sincerely,

Brock Samson

<<attachment: parsetest.zip>>

Reply via email to