Raml validator throws an error in javax.xml.validation.SchemaFactory.newSchema

扶醉桌前 提交于 2019-12-10 21:11:37

问题


When trying to validate espn.raml I got the below error. Same code is working fine for gmail.raml. Why is this happening? For your reference I have included the results I found what are the jars that SchemaFactory includes.

$ find *.jar | xargs grep SchemaFactory.class Binary file

axiom_1.2.11.wso2v6.jar matches Binary file

org.apache.openjpa_2.2.0.wso2v1.jar matches Binary file

solr_5.2.1.wso2v1.jar matches

This is the exception I'm getting:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.validation.SchemaFactory.newSchema(Ljavax/xml/transform/Source;)Ljavax/xml/validation/Schema;" the class loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) of the current class, org/raml/parser/rule/SchemaRule, and the class loader (instance of <bootloader>) for resolved class, javax/xml/validation/SchemaFactory, have different Class objects for the type m/Source;)Ljavax/xml/validation/Schema; used in the signature
    at org.raml.parser.rule.SchemaRule.doValidateValue(SchemaRule.java:118)
    at org.raml.parser.rule.SchemaRule.doValidateValue(SchemaRule.java:48)
    at org.raml.parser.rule.DefaultTupleRule.validateValue(DefaultTupleRule.java:108)
    at org.raml.parser.visitor.YamlDocumentValidator.onScalar(YamlDocumentValidator.java:115)
    at org.raml.parser.visitor.NodeVisitor.visitScalar(NodeVisitor.java:256)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:222)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitMappingNode(NodeVisitor.java:86)
    at org.raml.parser.visitor.NodeVisitor.visit(NodeVisitor.java:218)
    at org.raml.parser.visitor.NodeVisitor.visitResolvedNode(NodeVisitor.java:180)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:151)
    at org.raml.parser.visitor.NodeVisitor.visitDocument(NodeVisitor.java:209)
    at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:65)
    at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:95)
    at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:82)
    at org.raml.parser.visitor.YamlValidationService.validate(YamlValidationService.java:72)
    at org.wso2.carbon.registry.custom.extensions.handlers.utils.RAMLProcessor.isValidateRAML(RAMLProcessor.java:127)
    at org.wso2.carbon.registry.custom.extensions.handlers.utils.RAMLProcessor.processRAML(RAMLProcessor.java:79)
    at org.wso2.carbon.registry.custom.extensions.handlers.RAMLMediaTypeHandler.put(RAMLMediaTypeHandler.java:157)
    at org.wso2.carbon.registry.core.jdbc.handlers.HandlerManager.put(HandlerManager.java:2503)
    ... 78 more

回答1:


This is weird. I have no problem running the following:

RamlValidationService
  .createDefault()
  .validate("http://api.apihub.com/onpositive/api/espn-raml-api/espn.raml");

It throws no exception and returns an empty List<ValidationResult>, as this RAML file is valid.

My environment:

Apache Maven 3.3.3
Java version: 1.8.0_60, vendor: Oracle Corporation

In my case, javax.xml.validation.SchemaFactory is provided by the JDK itself. You should strive for the same, ie make sure that no other library can contribute this class to your code, either by using alternate JARs that don't contain this class (these seem to be WSO2 specific versions, other versions may be different?) or by using classloader filtering, if the execution environment allows it.

EDIT As added in the comments, the fix was to exclude xml-apis:xml-apis from RAML Parser. This exclusion makes sense since recent JDKs provided what's needed by RAML Parser.




回答2:


Excluding xml-apis from raml-parser did the job.

<exclusion>
 <groupId>xml-apis</groupId>
 <artifactId>xml-apis</artifactId>
</exclusion>

Now its validating without a issue.



来源:https://stackoverflow.com/questions/32570593/raml-validator-throws-an-error-in-javax-xml-validation-schemafactory-newschema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!