Mule - How to do a choice/when based on http response codes?

て烟熏妆下的殇ゞ 提交于 2019-12-20 06:17:03

问题


I need to be able to perform certain actions based on the http response code I get back from an http outbound endpoint. For instance if I get a 500 error or a 302 redirect or a 200. I need a way to evaluate the 500, 302, 200. I know how to use Choice-When, but don't know how to access the response code using groovy or whatever you suggest.


回答1:


You can get the HTTP response code with the following expression right after the HTTP outbound endpoint:

#[message.inboundProperties['http.status']]

Likewise in a Groovy script:

message.getInboundProperty('http.status')



回答2:


Seba is right but that is not enough.

By default, if an client or server error is detected in an HTTP outbound interaction (ie response code >= 400), Mule will treat the response as an error and will break the flow execution and call the exception strategy to deal with the error.

You need to deactivate this behaviour before doing the HTTP outbound interaction in order to have the rest of the flow (your choice router) be called. So you need this:

<set-variable variableName="http.disable.status.code.exception.check"
              value="true" />

before your HTTP outbound endpoint.



来源:https://stackoverflow.com/questions/16482500/mule-how-to-do-a-choice-when-based-on-http-response-codes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!