我从队列中提取数据,然后使用 int-xml:validating-filter 验证输入有效负载。我设置了 throw-exception-on-rejection =“true” ,以便引发异常。
我需要掌握异常消息(验证错误)以及输入有效负载。您能否建议可用于捕获此数据的选项?
<int-jms:message-driven-channel-adapter id="jmsIn"
destination="requestQueue" channel="orderChannel"/>
<int-xml:validating-filter id="validatingFilter"
input-channel="orderChannel"
output-channel="validOutputChannel"
discard-channel="errOutputChannel"
schema-type="xml-schema"
throw-exception-on-rejection="true"
schema-location="OrderProcessing/order.xsd"/>
最佳答案
您是否担心尚不清楚,是否可以捕获该异常。XmlValidatingMessageSelector
中的代码如下所示:
if (this.throwExceptionOnRejection) {
throw new MessageRejectedException(message, "Message was rejected due to XML Validation errors",
new AggregatedXmlMessageValidationException(
Arrays.<Throwable>asList(validationExceptions)));
}
因此,该
MessageRejectedException
具有所需的message
作为验证失败的原因。并且所有验证错误都表示在该AggregatedXmlMessageValidationException
的cause
MessageRejectedException
中。
关于spring - 使用<int-xml :validating-filter>时捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38444321/