在javax.xml. validate . schemafactory . newschema中抛出错误



尝试验证espn时。我得到了下面的错误。相同的代码可以很好地用于gmail.raml。为什么会发生这种情况?为了供您参考,我已经包含了我发现SchemaFactory包含的jar的结果。

$ find *.jar | xargs grep SchemaFactory.class二进制文件

axiom_1.2.11.wso2v6.jar匹配二进制文件

org.apache.openjpa_2.2.0.wso2v1.jar匹配二进制文件

solr_5.2.1.wso2v1.jar匹配

这是我得到的例外:

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

这很奇怪。运行以下命令没有问题:

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

它不抛出异常,并返回一个空的List<ValidationResult>,因为这个RAML文件是有效的。

我环境:

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

在我的例子中,javax.xml.validation.SchemaFactory是由JDK本身提供的。你应该努力做到这一点,即确保没有其他库可以为你的代码贡献这个类,要么使用不包含这个类的备用jar(这些似乎是WSO2特定的版本,其他版本可能不同?),要么使用类加载器过滤,如果执行环境允许的话。

EDIT正如在评论中添加的,修复是将xml-apis:xml-apis从RAML解析器中排除。这种排除是有意义的,因为最近的jdk提供了RAML Parser所需的东西。

将xml-api从raml-parser中排除就完成了任务。

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

现在验证没有问题

相关内容

  • 没有找到相关文章