我在链组件中有以下Spring组合代码:
<int:chain input-channel="PQIssueDetails-PQMemberSearchMemAltID-Request" output-channel="PQIssueDetails-PQMemberSearchRequest-CheckLegacySystem">
<!-- Transformer to transform the resultXml to the user understandable form using XSLT -->
<int-xml:xslt-transformer xsl-resource="${stylesheet.PQIssueDetailsPQMemberSearchMemAltIDRequest}"/>
<!-- Store the original payload in header for future purpose -->
<int:header-enricher default-overwrite="true" should-skip-nulls="true">
<int:header name="${headerNames.originalPayload}" expression="payload"/>
</int:header-enricher>
<!-- Store the original payload in header for future purpose -->
<int-xml:xpath-header-enricher default-overwrite="true" id="ToWorkForMembSearch" should-skip-nulls="true">
<int-xml:header name="legacySystem" evaluation-type="STRING_RESULT" overwrite="true" xpath-expression="//MemberSearch/LegacySystem"/>
<int-xml:header name="businessArea" evaluation-type="STRING_RESULT" overwrite="true" xpath-expression="//MemberSearch/businessArea"/>
</int-xml:xpath-header-enricher>
</int:chain>
在一个场景中,转换后的xml如下:
<?xml version="1.0" encoding="UTF-8"?>
由于有效负载没有有效的xml字符串,xpath-header-enricher
抛出以下异常:
org.springframework.integration.MessagingException: failed to transform message headers
2016-02-16 12:34:54,431 WARN http-0.0.0.0-8080-3 [org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway] failure occurred in gateway sendAndReceive
org.springframework.integration.MessageDeliveryException: no channel resolved by router and no default output channel defined
如果将无效的xml传递给xpath-expression
,如何使用xpath-header-enricher
处理此方案。
简而言之,不应该停止执行流程,即使传递了无效的xml内容,也不应该抛出异常。
关于我所面临的问题的任何想法?
答案 0 :(得分:1)
不应停止执行流程
将标题扩展出链并通过网关调用它,并使用error-channel
来处理错误:
<int:chain input-channel="PQIssueDetails-PQMemberSearchMemAltID-Request" output-channel="PQIssueDetails-PQMemberSearchRequest-CheckLegacySystem">
...
<int:gateway request-channel="enrich" error-channel="enrichErrors"/>
</int:chain>
<int-xml:xpath-header-enricher input-channel="enrich"
default-overwrite="true" id="ToWorkForMembSearch" should-skip-nulls="true">
<int-xml:header name="legacySystem" evaluation-type="STRING_RESULT" overwrite="true" xpath-expression="//MemberSearch/LegacySystem"/>
<int-xml:header name="businessArea" evaluation-type="STRING_RESULT" overwrite="true" xpath-expression="//MemberSearch/businessArea"/>
</int-xml:xpath-header-enricher>
当变压器成功时,消息将转到链中的下一个元素;如果它引发异常,带有ErrorMessage
和MessagingException
属性的有效负载(failedMessage
)的cause
将转到错误通道;如果该通道上的流返回结果,它将转到链中的下一个元素。