Error thrown while instantiating WsdlValidator via file path & Nokogiri version >= 1.17.0
We are using wsdl_validator plugin to validate XML against the WSDL schema. WSDL schema path is provided as a parameter. Code sample:
require 'wsdl_validator'
if @wsdl_schema_path && !error
wsdl = WsdlValidator.new(@wsdl_schema_path)
wsdl_errors = wsdl.errors_for(doc)
if wsdl_errors.any?
@logger.error("Error validating XML against WSDL schema", :errors => wsdl_errors, :xml => data)
error = true
end
end
The problem appears when a Nokogiri version >= 1.17.0 is set. Until now, Nokogiri 1.16.8 was used and worked as expected.
# Gem dependencies we used
s.add_runtime_dependency 'logstash-core-plugin-api', ">= 1.60", "<= 2.99"
s.add_runtime_dependency 'wsdl_validator', "~> 0.2.0"
s.add_runtime_dependency 'wasabi', "= 3.8.0"
s.add_runtime_dependency 'nokogiri', "= 1.16.8"
s.add_runtime_dependency 'insist', "= 1.0.0"
Once 'nokogiri', "= 1.17.0" is set, the following error is thrown:
1) LogStash::Codecs::Xml#decode using `wsdl_schema_path` option should return `message` field with valid XML content
Failure/Error: Unable to infer file and line number from backtrace
Java::OrgW3cDom::DOMException:
NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
# org.apache.xerces.dom.AttrNSImpl.setName(Unknown Source)
# org.apache.xerces.dom.AttrNSImpl.<init>(Unknown Source)
# org.apache.xerces.dom.CoreDocumentImpl.createAttributeNS(Unknown Source)
# org.apache.xerces.dom.ElementImpl.setAttributeNS(Unknown Source)
# nokogiri.XmlNode.setAttribute(XmlNode.java:1431)
# nokogiri.XmlNode.set(XmlNode.java:1403)
# nokogiri.XmlNode$INVOKER$i$2$0$set_DBG.call(XmlNode$INVOKER$i$2$0$set_DBG.gen)
Based on the release notes of Nokogiri 1.17.0, they made a lot of changes & improvements: https://github.com/sparklemotion/nokogiri/releases/tag/v1.17.0
Java & JRuby versions used:
$ java -version
openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-120.04.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-120.04.1, mixed mode, sharing)
$ jruby -v
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913fda OpenJDK 64-Bit Server VM 17.0.10+7-Ubuntu-120.04.1 on 17.0.10+7-Ubuntu-120.04.1 +jit [x86_64-linux]
Could you please provide a solution for the above-mentioned issue?
Thank you!
Edited by Cosmin Pietraru