使用<int-xml:validating-filter>时捕获异常

时间:2016-07-18 19:13:46

标签: spring exception error-handling spring-integration

我从队列中提取数据,然后使用 int-xml:validating-filter 验证输入有效负载。我已设置 throw-exception-on-rejection =&#34; true&#34; 以便抛出异常。

我需要掌握异常消息(验证错误)以及输入有效负载。您能否建议可用于捕获此数据的选项?

<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"/>

1 个答案:

答案 0 :(得分:1)

如果你能抓住那个例外,那么你并不清楚。

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的{​​{1}} cause