Validation 骆驼验证组件不工作

Validation 骆驼验证组件不工作,validation,xsd,apache-camel,schema,Validation,Xsd,Apache Camel,Schema,我的骆驼cxf(2.15.2)路线运行良好。然后需求要求我们需要根据xsd验证soap请求。我尝试添加验证程序组件: from ("direct:xxx") .to("validator:/path/to/CustomerRequest.xsd") My CustomerRequest.xsd已导入其他xsd 我仔细检查了xsd中的所有引用是否正常 现在,奇怪的是,如果我更改导入的顺序:首先是Address,然后是CustSourceEnum: <xsd:import schem

我的骆驼cxf(2.15.2)路线运行良好。然后需求要求我们需要根据xsd验证soap请求。我尝试添加验证程序组件:

from ("direct:xxx")  
  .to("validator:/path/to/CustomerRequest.xsd")
My CustomerRequest.xsd已导入其他xsd

我仔细检查了xsd中的所有引用是否正常

现在,奇怪的是,如果我更改导入的顺序:首先是Address,然后是CustSourceEnum:

<xsd:import schemaLocation="../vo/CustSourceEnum.xsd" namespace="http://vo.customer.com"></xsd:import>
<xsd:import schemaLocation="../vo/Address.xsd" namespace="http://vo.customer.com" />

然后仍然会发生错误,但现在它会抱怨“vo:Address”。
如果我试图修改
CustomerRequest.xsd
只导入一个模式,那么它就可以工作。当然,如果我删除了camel验证器组件,那么一切都会恢复正常。

您的问题是,您试图从多个文件导入相同的名称空间,这不是一个好主意。应用程序只导入第一个文件,并跳过具有相同命名空间的其他文件。关于这个问题,有一个很好的答案,以及可能的解决方法:


但更好的办法是为每个xsd文件创建一个名称空间。

我刚刚从xsd生成了xml文件(使用xml工具),然后在根据xsd验证该xml文件时出错。在调试com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema中的代码时,我没有更改xsd中的任何内容。我看到xerces只识别第一个导入xsd。
 org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[validator:/path/to/xsd/CustomerRequest.xsd]. 
 Reason: org.xml.sax.SAXParseException; lineNumber: 27; columnNumber: 115; src-resolve: Cannot resolve the name 'vo:CustSourceEnum' to a(n) 'type definition' component.
    at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:407)
    ...
Caused by: org.xml.sax.SAXParseException; lineNumber: 27; columnNumber: 115; src-resolve: Cannot resolve the name 'vo:CustSourceEnum' to a(n) 'type definition' component.  
<xsd:import schemaLocation="../vo/CustSourceEnum.xsd" namespace="http://vo.customer.com"></xsd:import>
<xsd:import schemaLocation="../vo/Address.xsd" namespace="http://vo.customer.com" />