Hi JB

I know you are quite busy so no need to apologize.

Just to make sure I understood you correctly, the 
org.apache.karaf.specs.java.xml-4.2.10.jar can be permanently removed from the 
/endorsed dir without any negative side effects, right?

________________________________
From: Jean-Baptiste Onofre <j...@nanthrax.net>
Sent: Wednesday, March 3, 2021 12:14 AM
To: user <user@karaf.apache.org>
Subject: Re: Karaf 4.2.10 - NullPointerException during xml parsing

Hi Brock,

Sorry for the very late answer.

The reason why javax.xml is in lib/endorsed folder is because core Karaf loads 
just the spec and let you install the impl.
Anyway, you can remove it from endorsed and install bundles, it works as well.
It’s basically what we plan to do by default as part of KARAF-6703.

Regards
JB

Le 3 mars 2021 à 05:50, brock samson 
<brock.sams...@hotmail.com<mailto:brock.sams...@hotmail.com>> a écrit :

Hi João

Thank you for looking into this issue. Its nice to know it no longer appears in 
karaf 4.3, but is there another way to resolve this in 4.2.10 without changing 
the code? More specifically, is there a reason why 
org.apache.karaf.specs.java.xml-4.2.10.jar resides in the /endorsed directory 
as opposed to being exposed by a bundle? The reason for me asking is because 
the bundle approach would allow me to choose which implementation my bundle 
would reference, while the current endorsed approach leaves me no choice.

Regards,

Brock

________________________________
From: João Assunção 
<joao.assun...@exploitsys.com<mailto:joao.assun...@exploitsys.com>>
Sent: Tuesday, March 2, 2021 5:28 PM
To: user@karaf.apache.org<mailto:user@karaf.apache.org> 
<user@karaf.apache.org<mailto:user@karaf.apache.org>>
Subject: Re: Karaf 4.2.10 - NullPointerException during xml parsing

Hi Brock,

I tried your jar but it failed due to the layout of the jar (the MANIFEST was 
not the first entry in the jar or something like that). I created a bundle with 
our code and when I tried with karaf 4.3 it passed.
I then tried with 4.2.7 and I experienced the same NPE. Apparently the behavior 
when the errorHandler is set to null is different between implementations of 
the XML libs supplied in these two versions of karaf.
In your code setting the error handler to builder.setErrorHandler(new 
org.xml.sax.helpers.DefaultHandler()); seems to do the trick.

I noticed your manifest is importing a bunch of packages not required for the 
code in question.

Regards
João Assunção

Email: joao.assun...@exploitsys.com<mailto:joao.assun...@exploitsys.com>
Mobile: +351 916968984
Phone: +351 211933149
Web: www.exploitsys.com<http://www.exploitsys.com/>




On Tue, Mar 2, 2021 at 3:33 AM brock samson 
<brock.sams...@hotmail.com<mailto:brock.sams...@hotmail.com>> wrote:
hi, JB. did you get a chance to run my bundle?

________________________________
From: brock samson <brock.sams...@hotmail.com<mailto:brock.sams...@hotmail.com>>
Sent: Wednesday, February 24, 2021, 11:18 PM
To: user@karaf.apache.org<mailto:user@karaf.apache.org>
Subject: Re: Karaf 4.2.10 - NullPointerException during xml parsing

hi, JB.

thank you for looking at this. The attached zip (rename its extension from .txt 
to .zip) contains both the bundle (rename its extension from .txt to .jar) 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<mailto:j...@nanthrax.net>>
Sent: Tuesday, February 23, 2021 11:56 AM
To: user@karaf.apache.org<mailto:user@karaf.apache.org> 
<user@karaf.apache.org<mailto: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

Reply via email to