【问题标题】:Catching exceptions when using <int-xml:validating-filter>使用 <int-xml:validating-filter> 时捕获异常
【发布时间】:2016-11-21 12:14:05
【问题描述】:

我正在从队列中提取数据,然后使用 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"/>

【问题讨论】:

    标签: spring exception error-handling spring-integration


    【解决方案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 causeMessageRejectedException 中。

    【讨论】:

    • 感谢@Artem Bilan 的回复
    • 我正在寻找在 中捕获异常的选项。我假设 会在丢弃通道或输出通道中提供异常。现在我明白了,由于抛出异常,调用者必须处理它。在我的特殊情况下,我在 中添加了错误通道,现在我能够从中捕获验证错误消息以及实际有效负载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多