【问题标题】:Keep executing flow even with a 404 response即使有 404 响应,也可以继续执行流程
【发布时间】:2016-06-14 16:15:44
【问题描述】:

我有以下 http 请求:

<http:request config-ref="FlowVarsHostAndPort" path="/rest/bpo/evento" method="POST" doc:name="Envia movimentacoes para Elaw Correspondente">
                    <http:request-builder>
                        <http:header headerName="Content-Type" value="application/json"/>
                    </http:request-builder>
                </http:request>

此服务在 foreach 中,当它返回 200 时它很好,但是当它返回 404 时它会抛出异常并且流程停止,我需要当服务返回给我 404 时我查看有效负载并确定它是否需要继续执行流程,我该如何实现?

我尝试使用 catch 异常策略但没有成功。

ps:当我在寻找不存在的资源时,服务将返回 404,响应示例:

{
  "processo": "0009843-63.2016.8.13.0301",
  "mensagem": "Não foi possivel encontrar o processo"
}

【问题讨论】:

    标签: mule


    【解决方案1】:

    在 HTTP 调用之前,需要禁用不抛出状态码异常的行为。在这种情况下,我们可以查看带有状态码的 HTTP 响应并执行任何需要的逻辑。

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

    反过来

    如果您只想限制 404。使用 SuccessStatusCode 验证器对 HTTP 说 404 是成功响应之一。

     <http:request config-ref="" path="/rest/bpo/evento" method="POST" doc:name="Envia movimentacoes para Elaw Correspondente">
                    <http:request-builder>
                    <http:header headerName="Content-Type" value="application/json"/>
                    </http:request-builder>
                <http:success-status-code-validator values="200,404"/>
      </http:request>
    

    参考:https://docs.mulesoft.com/mule-user-guide/v/3.7/http-request-connector。检查此参考网址中的HTTP Response validation 部分。

    【讨论】:

      猜你喜欢
      • 2022-11-02
      • 1970-01-01
      • 2013-05-12
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 2019-10-29
      相关资源
      最近更新 更多