Mule 如何在异常对象中查找Http错误负载?
如何在异常对象中查找Http错误负载 系统1->呼叫的Mule服务器。Mule服务器->文档签名/其他人 Docusign/有人返回400个错误,其中json负载包括错误代码等 我需要将确切的细节返回System 1 我该怎么做 1我尝试在成功代码200..599中添加所有代码,然后即使错误也有200 ok。这将导致更多的问题,因为我必须添加很多选择路由,因为一些流有更多的数据转换 2理想解决方案->像往常一样引发异常。这必须在选择异常中捕获。现在我必须将相同的状态代码和json响应发送回调用方Mule 如何在异常对象中查找Http错误负载?,mule,mule-studio,mule-component,mule-esb,Mule,Mule Studio,Mule Component,Mule Esb,如何在异常对象中查找Http错误负载 系统1->呼叫的Mule服务器。Mule服务器->文档签名/其他人 Docusign/有人返回400个错误,其中json负载包括错误代码等 我需要将确切的细节返回System 1 我该怎么做 1我尝试在成功代码200..599中添加所有代码,然后即使错误也有200 ok。这将导致更多的问题,因为我必须添加很多选择路由,因为一些流有更多的数据转换 2理想解决方案->像往常一样引发异常。这必须在选择异常中捕获。现在我必须将相同的状态代码和json响应发送回调用方
问题-?如何在异常对象中找到HTTP返回的有效负载。其中存储在异常对象中。以下是示例-处理此类场景的一种方法,使用验证组件通过exceptionHandling或APIKIT exceptionHandling在主流中引发异常和捕获
<flow name="routeexceptionFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/in" method="POST" doc:name="HTTP">
<http:success-status-code-validator values="200..599"/>
</http:request>
<validation:is-false config-ref="Validation_Configuration" message="#[payload]" exceptionClass="nz.co.exception.BadRequestException" expression="#[message.inboundProperties['http.status'] ==400]" doc:name="Validate Bad Request"/>
<validation:is-false config-ref="Validation_Configuration" message="#[payload]" expression="#[message.inboundProperties['http.status'] !=200]" doc:name="Capture all other Exceptions"/>
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches('nz.co.exception.BadRequestException')]" doc:name="Catch Exception Strategy">
<set-payload value="#[exception.message]" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger message="****log all other exception****" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
在您的项目中,如果您使用的是APIKIT路由器,那么不要像上面那样使用异常处理,而是直接将nz.co.exception.BadRequestException添加到400 ReturnCode APIKIT exceptionHandling中。我使用了与soln类似的东西。谢谢你
package nz.co.exception;
public class BadRequestException extends Exception {
private static final long serialVersionUID = 8546839078847602529L;
public BadRequestException() {
super();
}
public BadRequestException(String message) {
super(message);
}
public BadRequestException(Throwable t) {
super(t);
}
public BadRequestException(String message, Throwable t) {
super(message, t);
}
}