【发布时间】:2019-11-13 20:12:29
【问题描述】:
我设置了一个引擎来验证给定端点上的xml。localhost/rules/my-rule,如果xml 文件是一致的,它将返回xml 内容。但是,如果不是,则会引发异常:
GeneralException:组合不匹配
这是我声明的一个例外。这是一个正常的 Java 异常。
当我使用邮递员之类的工具发布错误文件时,我得到以下结果:
Can't invoke perform method on "class %rule class%" with request data of
"%data sent to endpoint%"
(reason: ch.package.GeneralException: Combination missmatch). Combination missmatch
这将是完美的。然而,在用骡子发送它时,我得到:
路由 0:在异常策略中捕获异常:资源“http://localhost/rules/my-rule/executions”上的 HTTP POST 失败:错误请求 (400)。
为什么我不能只收到错误消息?查看日志时没有更多见解:
org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation { 描述=资源上的 HTTP POST 'http://localhost/rules/my-rule/executions' 失败:错误请求 (400)。 detailDescription=资源上的 HTTP POST 'http://localhost/rules/my-rule/executions' 失败:错误请求 (400)。 errorType=HTTP:BAD_REQUEST
原因=org.mule.extension.http.api.request.validator.ResponseValidatorTypedException 错误消息= org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation {
有效载荷=org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider@3239ebf7 媒体类型=文本/纯文本;字符集=UTF-8
属性=org.mule.extension.http.api.HttpResponseAttributes {
状态码=400 原因短语=标题=[ 内容类型=文本/纯文本 传输编码=分块 日期=格林威治标准时间 2019 年 7 月 3 日星期三 07:16:19 connection=close ] } attributesMediaType=/ } childErrors=[] }] }
我的流程配置:
<scatter-gather doc:name="Distribute workload" doc:id="15151949-c61d-4629-9fd4-0a4e16d62eec" >
<route >
<!--Access to localhost/rules/my-rule>
<flow-ref doc:name="CategoryToType" doc:id="e5d39afa-3b2a-45ef-81c0-afce77a76aef" name="validateCategoryToType" />
</route>
</scatter-gather>
<error-handler>
<on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="16001c58-7609-42a6-9bfa-1cd756998f27" >
<logger level="INFO" doc:name="Logger" doc:id="8ec2af18-3e45-4d15-a373-5e9af74723d7" message='#[error]'/>
</on-error-propagate>
</error-handler>
<sub-flow name="validateCategoryToType" doc:id="da38db3a-7d51-4fd1-bd06-9e58b872d468" >
<foreach doc:name="For Each" doc:id="ff9944ba-5f87-4a5a-9392-a4b27c2f5fb0" collection="payload.Kunden" rootMessageVariableName="Kunden">
<ee:transform doc:name="Transform Message" doc:id="f33fa5ea-0b4d-4ac5-a247-90fd6978248d">
<ee:message>
<ee:set-payload>
<!--Some transformy stuff-->
</ee:set-payload>
</ee:message>
</ee:transform>
<http:request method="POST" doc:name="Request" doc:id="53df928a-4fd1-4125-88e0-be73b006beee" config-ref="HTTP_Request_configuration" path="/rules/my-rule/execution>
<http:headers><![CDATA[#[output application/java
---
{
"Content-Type" : "application/xml",
"Accept" : "application/xml"
}]]]></http:headers>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="cc02312e-b71b-461c-bba0-077bfb1e9b7e" message="#[payload]" />
</foreach>
</sub-flow>
【问题讨论】:
-
嗨皮特,你定义了全局错误处理程序吗?您只会得到一般的错误响应
-
错误处理程序仅在流范围内。据我所知,每个子流程都会写在主流程的错误处理程序上,我弄错了吗?
-
您使用的是哪个版本的 Mule ?
-
我使用的是最新版本 4.2
-
我会说定义全局处理程序并引用它,或者在 logger 之前使用 dataweave ,error.errordescription dzone.com/articles/error-handling-in-mule-1
标签: java rest exception request mule