Mule HTTP端点返回状态500,但不会引发异常

时间:2014-10-06 16:20:05

标签: http mule

我的流中的传出HTTP端点返回状态500,但是Mule不会抛出任何异常。当我逐步调试流程时,在HTTP调用之后显然存在异常有效负载,但是流程一直持续到结束:

<flow name="pocFlow2" doc:name="pocFlow2">
    <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" path="poc/error" doc:name="HTTP"/>
    <!-- This one returns 500 error -->
    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/>
    <object-to-string-transformer doc:name="Object to String"/>
    <set-payload value="All good" doc:name="Set Payload"/>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <logger level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
</flow>

这是预期的行为吗?每次HTTP调用后我是否必须自己抛出错误?

1 个答案:

答案 0 :(得分:0)

是的,您需要检查响应的状态代码并采取适当的操作。 Mule不知道您正在拨打什么电话或者您期望的状态代码,因此http连接器不会抛出异常。关于Mule的一个令人烦恼的事情是,没有一种简单的方法可以抛出异常。我已经编写了一个非常简单的小ExceptionThrower java类来处理这种情况。

    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/>
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties['http.status'] == '200']">
            <!-- Handle my payload -->
        </when>
        <otherwise>
            <!-- This isn't what I expected, so throw an exception to let the catch-exception-strategy handle it. -->
            <component class="com.example.ExceptionThrower" doc:name="Java"/>
        </otherwise>
    </choice>
相关问题