We are attempting to use the xmlunit-core library methods in an OSGi application. At runtime, we ran into a situation where the TransformerFactory class was not being resolved. I have included below an explaination of a modification to the xml unit code that we used to address this issue. We are wondering if there is an existing mechanim to address OSGI loading? If not, is there any interest in developing a feature so that we do not have to maintain a separate library with the changes we needed?
I don't use OSGi myself and am not intimately familiar with it. I've tried to setup things in a way, that should allow all modules to be used as OSGi bundles, so supporting the environment is a goal.
OTOH we do want to support people switching the TransformerFactory using JAXP mechanisms. It is unfortunate this seems to be incompatible with OSGi. Your patch as you describe it, would hard-code Saxon for everybody, which cannot be a goal at all.
I think it is possible to pass a TransformerFactory into XMLUnit's execution contexts explicitly. At least for Convert and Transformation do allow you to specify a factory yourself, DefaultComparisonFormatter doesn't allow this right now, but you could override createXmlTransformer which looks totally inconvenient.
So I feel we need to change DefaultComparisonFormatter but for your other use cases you should be able to provide a TransformerFactory you've created yourself before invoking XMLUnit.
How do you use XMLUnit from your code? I'm not sure the API allows to specify a consistent factory from everywhere.
Stefan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I realize that my patch is not a long term solution to the issue I just did that to make sure that was the root cause of the issue. We are using the library to compare two xml files so we would need a mechanism to allow us to specify the transform factory in the DefaultComparisonFormatter.
I don't use OSGi myself and am not intimately familiar with it. I've tried to setup things in a way, that should allow all modules to be used as OSGi bundles, so supporting the environment is a goal.
OTOH we do want to support people switching the TransformerFactory using JAXP mechanisms. It is unfortunate this seems to be incompatible with OSGi. Your patch as you describe it, would hard-code Saxon for everybody, which cannot be a goal at all.
I think it is possible to pass a TransformerFactory into XMLUnit's execution contexts explicitly. At least for Convert and Transformation do allow you to specify a factory yourself, DefaultComparisonFormatter doesn't allow this right now, but you could override createXmlTransformer which looks totally inconvenient.
So I feel we need to change DefaultComparisonFormatter but for your other use cases you should be able to provide a TransformerFactory you've created yourself before invoking XMLUnit.
How do you use XMLUnit from your code? I'm not sure the API allows to specify a consistent factory from everywhere.
To whom it may concern,
We are attempting to use the xmlunit-core library methods in an OSGi application. At runtime, we ran into a situation where the TransformerFactory class was not being resolved. I have included below an explaination of a modification to the xml unit code that we used to address this issue. We are wondering if there is an existing mechanim to address OSGI loading? If not, is there any interest in developing a feature so that we do not have to maintain a separate library with the changes we needed?
Thanks
Jim
After googling the error we found the folowing link https://stackoverflow.com/questions/51687871/unable-to-force-eclipse-to-use-saxon-xslt-processor that suggests we use replace:
TransformerFactory fact = TransformerFactory.newInstance()
with
TransformerFactory fact = new net.sf.saxon.TransformerFactoryImpl();"
We successfully tested that this was our issue by making the following changes to the xmlunit-2.5.1 library code:
**xmlunit-core/src/main/java/org/xmlunit/diff/DefaultComparisonFormatter.java diffs: ***
30,31d29
< import net.sf.saxon.TransformerFactoryImpl;
<
457c455
< final TransformerFactory factory = new TransformerFactoryImpl();
** xmlunit-core/src/main/java/org/xmlunit/transform/Transformation.java diffs: ***
168c168
< fac = new net.sf.saxon.TransformerFactoryImp();
** xmlunit-core/src/main/java/org/xmlunit/util/Convert.java diffs: ***
34d33
< import net.sf.saxon.TransformerFactoryImpl;
76c75
< fac = new TransformerFactoryImpl();
Hi Jim
I don't use OSGi myself and am not intimately familiar with it. I've tried to setup things in a way, that should allow all modules to be used as OSGi bundles, so supporting the environment is a goal.
OTOH we do want to support people switching the
TransformerFactoryusing JAXP mechanisms. It is unfortunate this seems to be incompatible with OSGi. Your patch as you describe it, would hard-code Saxon for everybody, which cannot be a goal at all.I think it is possible to pass a
TransformerFactoryinto XMLUnit's execution contexts explicitly. At least forConvertandTransformationdo allow you to specify a factory yourself,DefaultComparisonFormatterdoesn't allow this right now, but you could overridecreateXmlTransformerwhich looks totally inconvenient.So I feel we need to change
DefaultComparisonFormatterbut for your other use cases you should be able to provide aTransformerFactoryyou've created yourself before invoking XMLUnit.How do you use XMLUnit from your code? I'm not sure the API allows to specify a consistent factory from everywhere.
Stefan
Hi Stefan,
I realize that my patch is not a long term solution to the issue I just did that to make sure that was the root cause of the issue. We are using the library to compare two xml files so we would need a mechanism to allow us to specify the transform factory in the DefaultComparisonFormatter.
Please let me know how you would like to proceed.
Jim
From: Stefan Bodewig bodewig@users.sourceforge.net
Sent: Tuesday, July 28, 2020 7:41 AM
To: [xmlunit:discussion] 73274@discussion.xmlunit.p.re.sourceforge.net
Subject: [xmlunit:discussion] Using xmlunit library in OSGI bundle
Hi Jim
I don't use OSGi myself and am not intimately familiar with it. I've tried to setup things in a way, that should allow all modules to be used as OSGi bundles, so supporting the environment is a goal.
OTOH we do want to support people switching the TransformerFactory using JAXP mechanisms. It is unfortunate this seems to be incompatible with OSGi. Your patch as you describe it, would hard-code Saxon for everybody, which cannot be a goal at all.
I think it is possible to pass a TransformerFactory into XMLUnit's execution contexts explicitly. At least for Convert and Transformation do allow you to specify a factory yourself, DefaultComparisonFormatter doesn't allow this right now, but you could override createXmlTransformer which looks totally inconvenient.
So I feel we need to change DefaultComparisonFormatter but for your other use cases you should be able to provide a TransformerFactory you've created yourself before invoking XMLUnit.
How do you use XMLUnit from your code? I'm not sure the API allows to specify a consistent factory from everywhere.
Stefan
Using xmlunit library in OSGI bundlehttps://urldefense.proofpoint.com/v2/url?u=https-3A__sourceforge.net_p_xmlunit_discussion_73274_thread_5de6851242_-3Flimit-3D25-23080f&d=DwMCAg&c=LFYZ-o9_HUMeMTSQicvjIg&r=M-yZXLdp1nyvpO-MD0jO7Q&m=PkaD5kZSuVvjNTguGMraX56JZ-bBpEzAN0Y8oALCfmo&s=ZwiVIXZU6-Xozv96Rln5uGtDDXcFjLTWFI0f6mPvLSY&e=
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/xmlunit/discussion/73274/https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceforge.net_p_xmlunit_discussion_73274_&d=DwMCAg&c=LFYZ-o9_HUMeMTSQicvjIg&r=M-yZXLdp1nyvpO-MD0jO7Q&m=PkaD5kZSuVvjNTguGMraX56JZ-bBpEzAN0Y8oALCfmo&s=CEj2zKUfb21QP-SC8RYFzdKmxIcfIVsNgHvZWHN8FEk&e=
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceforge.net_auth_subscriptions_&d=DwMCAg&c=LFYZ-o9_HUMeMTSQicvjIg&r=M-yZXLdp1nyvpO-MD0jO7Q&m=PkaD5kZSuVvjNTguGMraX56JZ-bBpEzAN0Y8oALCfmo&s=I1IadPXCP_5SnFGed2yYRxr-kPi5K3Eg9HxnRoPGYXs&e=
I've opened https://github.com/xmlunit/xmlunit/issues/195 and will get to it sometime in the coming weeks. If there is anything else you'd need please open new issues.
Thanks
Stefan
XMLUnit 2.8.0 has just been released and allows the
TransformerFactoryto be set explicitly inDefaultComparisonFormatter.