gpt4 book ai didi

java - 从 Mule 端点捕获错误 java 响应

转载 作者:行者123 更新时间:2023-11-30 05:34:46 26 4
gpt4 key购买 nike

我设置了一个引擎,可以在给定端点验证 xml
localhost/rules/my-rule,如果xml文件一致则返回xml内容。如果不是,则会抛出异常:

GeneralException: Combination missmatch

这是我声明的一个异常(exception)。这是一个普通的 Java 异常。
当我使用 postman 之类的工具发布错误文件时,我得到以下结果:

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

这将是完美的。然而,当我用骡子发送它时,我得到:

Route 0: Caught exception in Exception Strategy: HTTP POST on resource 'http://localhost/rules/my-rule/executions' failed: bad request (400).

为什么我无法获取错误消息?查看日志时没有更多的见解:

org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation { description=HTTP POST on resource 'http://localhost/rules/my-rule/executions' failed: bad request (400). detailedDescription=HTTP POST on resource 'http://localhost/rules/my-rule/executions' failed: bad request (400). errorType=HTTP:BAD_REQUEST
cause=org.mule.extension.http.api.request.validator.ResponseValidatorTypedException errorMessage= org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation {
payload=org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider@3239ebf7 mediaType=text/plain; charset=UTF-8
attributes=org.mule.extension.http.api.HttpResponseAttributes {
Status Code=400 Reason Phrase= Headers=[ content-type=text/plain transfer-encoding=chunked date=Wed, 03 Jul 2019 07:16:19 GMT 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>

最佳答案

使用全局错误处理程序,我已经为您编写了 HTTP 错误请求。您可以将其扩展到其他错误类型,例如 API 工具包等。

此外,通过创建变量并将 postman 负载捕获到变量中来扩展进一步的错误消息

<on-error-propagate type="HTTP:BAD_REQUEST"
enableNotifications="true" logException="true" doc:name="On Error Propagate"
doc:id="73b29eaf-ebcd-4857-baea-4c2fb963b055">
<set-variable value="#[400]" doc:name="HTTP Status - 400"
doc:id="4017a80c-f968-4f09-8fbb-eaa4ce5d1413" variableName="httpStatus" />
<set-variable
value="Service is unable to handle request"
doc:name="errorMessage" doc:id="9ab2b50b-7aad-4460-b276-f5d50ffd1efe"
variableName="errorMessage" />
<ee:transform doc:name="Transform Message" doc:id="df98f927-584c-454e-971e-79d2ff1e842d" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
error: {
errorCode: error.errorType.identifier,
errorDateTime: now() as String { format: "yyyy-MM-dd'T'HH:mm:ss" },
errorDescription: error.description
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<ee:transform doc:name="Transform Message" doc:id="6e6c0017-2b23-4bfa-83ef-2f77cc25aa08" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>

</on-error-propagate>

关于java - 从 Mule 端点捕获错误 java 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56865008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com