骡子 - 如何基于http响应代码做出选择/何时?

0 http endpoint mule

我需要能够根据从http出站端点返回的http响应代码执行某些操作.例如,如果我得到500错误或302重定向或200.我需要一种方法来评估500,302,200.我知道如何使用Choice-When,但不知道如何使用Choice访问响应代码groovy或你建议的任何东西.

Dav*_*sot 11

塞巴是对的但这还不够.

默认情况下,如果在HTTP出站交互中检测到客户端或服务器错误(即响应代码> = 400),Mule会将响应视为错误,并将中断流程执行并调用异常策略来处理错误.

您需要在执行HTTP出站交互之前停用此行为,以便choice调用其余流(您的路由器).所以你需要这个:

<set-variable variableName="http.disable.status.code.exception.check"
              value="true" />
Run Code Online (Sandbox Code Playgroud)

在HTTP出站端点之前.


Seb*_*eba 8

您可以在HTTP出站端点之后立即获取具有以下表达式的HTTP响应代码:

#[message.inboundProperties['http.status']]
Run Code Online (Sandbox Code Playgroud)

同样在Groovy脚本中:

message.getInboundProperty('http.status')
Run Code Online (Sandbox Code Playgroud)