首页 > 解决方案 > Mulesoft - 捕获 http 状态

问题描述

调用一个肥皂网络服务并使用一个 groovy 脚本检查网络服务响应的 http 状态。在 Mule 3 中,groovy 脚本是...

def httpStatus = message.getInboundProperty('http.status')
if (httpStatus == '400') {
     throw new Exception('Bad Request');
 }
return payload;

Mule 4中的等价物是什么?谢谢。

标签: mulesoft

解决方案


#[attributes.statusCode]是 Mule 3 #[inboundProperties.'http.status] 的等效表达式(https://docs.mulesoft.com/connectors/http/http-request-ref#map-between-http-responses-and-mule-messages)。如果属性映射到 Mule 4 中的 Groovy 脚本,我不记得我的想法,您需要尝试一下。

我建议避免使用 Groovy 或其他脚本语言进行错误处理,而是使用 Mule 内置的错误处理。


推荐阅读