骆驼验证组件不起作用
camel validation component does not work
我的 camel cxf (2.15.2) 路线工作正常。然后要求说我们需要根据 xsd 验证 soap 请求。我尝试添加验证器组件:
from ("direct:xxx")
.to("validator:/path/to/CustomerRequest.xsd")
我的 CustomerRequest.xsd 导入了其他 xsd(s)。
<xsd:import schemaLocation="../vo/Address.xsd" namespace="http://vo.customer.com" />
<xsd:import schemaLocation="../vo/CustSourceEnum.xsd" namespace="http://vo.customer.com"></xsd:import>
但是当我运行 启动应用程序时,出现错误。它抱怨 CustSourceEnum
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 中的所有引用都没有问题。
现在,奇怪的是如果我改变导入的顺序:首先是地址,然后是 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 文件创建一个命名空间。
我的 camel cxf (2.15.2) 路线工作正常。然后要求说我们需要根据 xsd 验证 soap 请求。我尝试添加验证器组件:
from ("direct:xxx")
.to("validator:/path/to/CustomerRequest.xsd")
我的 CustomerRequest.xsd 导入了其他 xsd(s)。
<xsd:import schemaLocation="../vo/Address.xsd" namespace="http://vo.customer.com" />
<xsd:import schemaLocation="../vo/CustSourceEnum.xsd" namespace="http://vo.customer.com"></xsd:import>
但是当我运行 启动应用程序时,出现错误。它抱怨 CustSourceEnum
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 中的所有引用都没有问题。
现在,奇怪的是如果我改变导入的顺序:首先是地址,然后是 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 文件创建一个命名空间。